python - 通过 python 自动化 .get 请求

标签 python python-3.x python-requests

我有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/

相关文章:

python请求post返回纯文本

python - 带有状态码 200 重定向的链接

python - 如何向下滚动并单击按钮以在python中连续抓取页面

python - 将单个 python 文件与 "extras"包一起打包

python - Pandas 在数据框中组合稀疏列

python - 在 Python 中解析多行

python - Mojave 上的 pyenv 在安装 3.5.6、3.6.7 时抛出未声明的标识符 'CLOCK_REALTIME' 和其他错误

python - 如何计算方法调用,但不计算属性访问?

python - 日志记录属性 asctime 生成本地时间

python-3.x - 如何使用 pandas 中的条件从两个 SQLite 表创建 Excel 文件?