python - 使用 requests.post 遍历多个 url
问题描述
例如,我有一个这样的列表(我有 100 个网址):
https://google.com
https://facebook.com
https://yahoo.com
https://stackoverflow.com
保存在cisco.txt 我在 python 中制作了这个脚本,在每个 url 上发出一个 post 请求并给我响应,但它只请求一个 url,所以我想遍历每个 url
import requests
import ssl
import sys
with open('cisco.txt') as fp:
for line in fp:
print(line)
request =(line)
data={'SAMLResponse':'test'}
response = requests.post(request, data, verify=False)
print(response.content)
解决方案
您应该在循环中完成所有操作。目前,最后一行将设置请求,然后您才开始提出一个请求。
import requests
import ssl
import sys
with open('cisco.txt') as fp:
for line in fp:
print(line)
request =(line)
# keep all of this in the loop
data={'SAMLResponse':'test'}
response = requests.post(request, data, verify=False)
print(response.content)
推荐阅读
- xml - XSLT for-each 循环转换
- angular - Validators.nullValidator(control: AbstractControl) 的意义何在?
- ios - 如何将负零与正零分开?
- dialogflow-es - 使用 google mini 设备进行测试时无法获取设备粗略位置
- android - “原生平台”在上传到 Play 商店时减少,并警告说“应用程序可用于在更少类型的设备上进行新安装”
- node.js - Angular 6 - 服务器未运行时未检测到现有文件的更改
- python - 从文件中提取存储的用户名和密码并通过python脚本使用它的有效方法是什么?
- javascript - 将组件更改为在 reactJS 中的功能
- python - 不是所有的参数都用在sql语句中,sql语句中的变量
- kubernetes - 我们如何在创建 configmap 时在 kubernetes 中使用数据源的 url