오늘은 누구나 잘 아는 거물이 개발한 Python 라이브러리 [filestools]를 소개합니다.
pip install filestools -i https://pypi.org/simple/ -U
# 这样即可将C盘,切换到D盘 C:\Users\Administrator>D: # 使用cd命令,可以切换到指定盘的指定目录 C:\Users\Administrator>cd C:\Users\Administrator\Desktop\python三剑客\加盟店爬虫
from treedir.tree import tree_dir tree_dir(r"C:\Users\Administrator\Desktop\python三剑客\加盟店爬虫", m_level=7, no_calc=False)
<span style="font-size: 15px;">a.txt</span>
文件,经过一段时间后,我对其中的内容做了修改,得到了最后的<span style="font-size: 15px;">b.txt</span>
。from filediff.diff import file_diff_compare file_diff_compare("a.txt", "b.txt")
<span style="font-size: 15px;">html</span>
网页文件。<span style="font-size: 15px;">黄色</span>
表示改动过的内容,<span style="font-size: 15px;">绿色</span>
表示新添加过的内容,<span style="font-size: 15px;">红色</span>
表示已经删除过的内容。from filediff.diff import file_diff_compare file_diff_compare(file1, file2, diff_out='diff_result.html', max_width=70, numlines=0, show_all=False, no_browser=False)
<span style="font-size: 15px;">Watermark Pictures</span>
<span style="font-size: 15px;">图片加水印</span>
Code, 사진에 워터마크를 추가하는 호출은 다음과 같습니다. 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_mark add_mark(file=r"C:\Users\Administrator\Desktop\大学.jpg", out=r"C:\Users\Administrator\Desktop\python三剑客\加盟店爬虫", mark="黄同学", opacity=0.2, angle=30, space=30)
<span style="font-size: 15px;">大学.jpg</span>
添加一个<span style="font-size: 15px;">黄同学</span>
水印,保存的位置在<span style="font-size: 15px;">加盟店爬虫</span>
文件夹下,透明度是<span style="font-size: 15px;">0.2</span>
,旋转角度是<span style="font-size: 15px;">30°</span>
,字体之间的间隔是<span style="font-size: 15px;">30</span>
。<code style='font-size: 14px;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);'><span style="font-size: 15px;">实习网</span>
Python 위치 인턴십 웹사이트 의 내용을 예시로 들었습니다. http://www.shixi.com/search/index?key=python
可以看到: 这里有各种不同的请求url,然后 <span style="font-size: 12px;">-H</span>
后面是该请求对应的各种参数。我们需要请求哪个链接,就复制对应的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 curlCmdGenPyScript curl_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)
위 내용은 추천 컬렉션 | 1개의 Python 라이브러리, 4개의 멋진 기능!의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!