我有a python script抓取页面,使用 jinja2 模板引擎输出适当的 HTML,感谢你们和 Coding Den Discord 的人们,我终于开始工作了。
我希望自动执行我在文件顶部发出的 .get 请求。
我有数以千计的 URL,我希望此脚本在其上运行。解决这个问题的好方法是什么?我试过使用一组 URL,但 requests
拒绝了。它提示必须是一个字符串。所以看来我每次都需要遍历 compiledUrls
变量。非常感谢有关该主题的任何建议。
最佳答案
使用 url 构建一个文本文件。
urls.txt
https://www.perfectimprints.com/custom-promos/20267/Pizza-Cutters1.html
https://www.perfectimprints.com/custom-promos/20267/Pizza-Cutters2.html
https://www.perfectimprints.com/custom-promos/20267/Pizza-Cutters3.html
https://www.perfectimprints.com/custom-promos/20267/Pizza-Cutters4.html
https://www.perfectimprints.com/custom-promos/20267/Pizza-Cutters5.html
获取url并处理:
with open("urls.txt") as file:
for single_url in file:
url = requests.get(single_url.strip())
..... # your code continue here
关于python - 通过 python 自动化 .get 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53014509/