问题描述
我一直在尝试处理请求和多线程。我已将requests
与ThreadPoolExecutor
一起使用,但事实证明是这样。由于阻塞或无阻塞IO
这是代码。我在用:
def request_handler(key):
page=requests.post(
'https://xxxxxx/website_link',#Link will remain same
headers=requestHeader,data=key+'POST DATA TO BE SENT') # key will be merged in POST data
print(key,threading.get_ident(),page.elapsed.total_seconds())
# Store the response in the database
keywords=['ABC','XYZ',......]
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
executor.map(request_handler,keywords)
我认为请求可以解决此问题,我找不到确切的解决方案。我已经看到请求一次接收多个URL。但就我而言,链接将保持不变,只是 POST 请求中的数据将被更改。 另外,如何获得每个关键字的单独响应并在我的代码中进行处理。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)