简体   繁体   English

如何使用 Python 发送多个 HTTP 请求

[英]How to send multiple HTTP requests using Python

I'm trying to create a script that checks all possible top level domain combinations based on a given root domain name.我正在尝试创建一个脚本,以根据给定的根域名检查所有可能的顶级域组合。

What I've done is generate a list of all possible TLD combinations and what I want to do is make multiple HTTP requests, analyze its results and determine whether a root domain name has multiple active top level domains or not.我所做的是生成所有可能的 TLD 组合的列表,我想做的是发出多个 HTTP 请求,分析其结果并确定根域名是否具有多个活动顶级域。

Example: A client of mine has this active domains:示例:我的一个客户有这个活动域:

  • domain.com域.com
  • domain.com.ar域.com.ar
  • domain.ar域.ar

I've tried using grequests but get this error:我尝试使用 grequests 但收到此错误:

TypeError: 'AsyncRequest' object is not iterable

Code:代码:

import grequests


responses = grequests.get([url for url in urls])
grequests.map(responses)

As I mentioned, you cannot put code as a parameter.正如我所提到的,您不能将代码作为参数。 What you want is to add a list and you can using an inline for loop, like this: [url for url in urls]您想要的是添加一个列表,您可以使用内联 for 循环,如下所示: [url for url in urls]

It is called list comprehensions and more information about this can be found over here: https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions它被称为列表理解,更多信息可以在这里找到: https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions

So I just added two brackets:所以我只是添加了两个括号:

import grequests

responses = (grequests.get(u) for u in urls)
grequests.map(responses)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何发送多个HTTP请求python - How to send multiple http requests python Python:我如何发送多个HTTP请求并接收响应? - Python: How can i send multiple HTTP requests and receive the response? 如何使用python请求在同一连接中发送多个post请求 - How to send multiple post requests in same connection using python requests 如何使用Python同时发送10,000个HTTP请求 - How to send 10,000 HTTP requests concurrently using Python 有没有办法使用 python requests 模块形成批处理请求? 我想在单个 POST 请求中发送多个同质 http API 请求 - Is there a way to form batched requests using python requests module ? I want to send multiple homogenous http API requests in a single POST request 如何使用 grerequests 发送数千个 HTTP 请求? - How to send thousands of HTTP Requests using grerequests? Python:如何同时发送多个http请求? (如叉子) - Python: How can i send multiple http requests at the same time? (like fork) 如何使用Python向网站发送多个获取请求? - How to send multiple get requests to a website in Python? 如何使用 threadpoolexecutor 和请求在 python 中发送具有多个请求的有效负载? - how can i send payload with multiple requests in python using threadpoolexecutor and requests? 如何使用 Http.Client 在 Python 中加速多个顺序 http 请求 - How to speed up multiple sequential http requests in Python using Http.Client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM