[英]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:示例:我的一个客户有这个活动域:
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.