通过python自动执行.get请求

帕特里克

我有一个抓取页面的python脚本,使用jinja2模板引擎输出适当的HTML,最终终于开始工作了,这要归功于您的好心人和The Coding Den Discord的支持。

我想自动化在文件顶部的.get请求。

我有成千上万个要运行此脚本的URL。有什么好的方法可以解决这个问题?我试过使用URL数组,但requests对此拒绝它抱怨必须是一个字符串。因此,似乎compiledUrls每次都需要遍历该变量。关于这个问题的任何建议将不胜感激。

番荔枝

使用网址构建文本文件。

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

获取网址和流程

with open("urls.txt") as file:
    for single_url in file:
        url = requests.get(single_url.strip())
        ..... # your code continue here

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章