今天介绍一个Python库【filestools】,是由一位大家很熟悉的大佬开发的。
pip install filestools -i https://pypi.org/simple/ -U
1. 树形目录显示
# 这样即可将C盘,切换到D盘C:\Users\Administrator>D:# 使用cd命令,可以切换到指定盘的指定目录C:\Users\Administrator>cd C:\Users\Administrator\Desktop\python三剑客\加盟店爬虫
from treedir.tree import tree_dirtree_dir(r"C:\Users\Administrator\Desktop\python三剑客\加盟店爬虫", m_level=7, no_calc=False)
2. 文本文件差异比较
a.txt
文件,经过一段时间后,我对其中的内容做了修改,得到了最后的b.txt
。from filediff.diff import file_diff_comparefile_diff_compare("a.txt", "b.txt")
html
网页文件。黄色
表示改动过的内容,绿色
表示新添加过的内容,红色
表示已经删除过的内容。from filediff.diff import file_diff_comparefile_diff_compare(file1, file2, diff_out='diff_result.html', max_width=70, numlines=0, show_all=False, no_browser=False)
3. 图片加水印
图片加水印
代码,给图片加水印调用的是add_mark()函数。from watermarker.marker import add_mark# 注意:有些参数是默认参数,你可以随意修改的;add_mark(file, mark, out='output', color='#8B8B1B', size=30, opacity=0.15, space=75, angle=30)
from watermarker.marker import add_markadd_mark(file=r"C:\Users\Administrator\Desktop\大学.jpg", out=r"C:\Users\Administrator\Desktop\python三剑客\加盟店爬虫", mark="黄同学", opacity=0.2, angle=30, space=30)
大学.jpg
添加一个黄同学
水印,保存的位置在加盟店爬虫
文件夹下,透明度是0.2
,旋转角度是30°
,字体之间的间隔是30
。4. curl网络请求转requests库请求代码
实习网
的Python岗位为例,进行说明。-H
后面是该请求对应的各种参数。我们需要请求哪个链接,就复制对应的curl。curl 'http://www.shixi.com/search/index?key=python' \ -H 'Connection: keep-alive' \ -H 'Cache-Control: max-age=0' \ -H 'Upgrade-Insecure-Requests: 1' \ -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' \ -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \ -H 'Referer: http://www.shixi.com/' \ -H 'Accept-Language: zh-CN,zh;q=0.9' \ -H 'Cookie: UM_distinctid=17a50a2c8ea537-046c01e944e72f-6373267-100200-17a50a2c8eb4ff; PHPSESSID=rpprvtdrcrvt54fkr7msgcde17; CNZZDATA1261027457=1711789791-1624850487-https%253A%252F%252Fwww.baidu.com%252F%7C1627741311; Hm_lvt_536f42de0bcce9241264ac5d50172db7=1627741268; Hm_lpvt_536f42de0bcce9241264ac5d50172db7=1627741334' \ --compressed \ --insecure
from curl2py.curlParseTool import curlCmdGenPyScriptcurl_cmd = """curl 'http://www.shixi.com/search/index?key=python' \ -H 'Connection: keep-alive' \ -H 'Cache-Control: max-age=0' \ -H 'Upgrade-Insecure-Requests: 1' \ -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' \ -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \ -H 'Referer: http://www.shixi.com/' \ -H 'Accept-Language: zh-CN,zh;q=0.9' \ -H 'Cookie: UM_distinctid=17a50a2c8ea537-046c01e944e72f-6373267-100200-17a50a2c8eb4ff; PHPSESSID=rpprvtdrcrvt54fkr7msgcde17; CNZZDATA1261027457=1711789791-1624850487-https%253A%252F%252Fwww.baidu.com%252F%7C1627741311; Hm_lvt_536f42de0bcce9241264ac5d50172db7=1627741268; Hm_lpvt_536f42de0bcce9241264ac5d50172db7=1627741334' \ --compressed \ --insecure"""output = curlCmdGenPyScript(curl_cmd)print(output)
【感谢龙石为本站提供api接口平台 /pages/apigateway.html】只有一条路不能拒绝——那就是成长的路。