问题描述
我正试图从一个URL下载2万个页面,并且我需要我的IP每隔两千(或大约)个请求进行切换,以免出现ssl错误或“被淘汰”
我目前求助于一次要问两千页的问题,这可想而知。
for cnt,ticker in enumerate(sif_df["ticker"][begloc_int:endloc_int]):
composite_urlstr = urlstr + ticker + suffix_urlstr
#print(composite_urlstr)
html_list.append(fetch(session,composite_urlstr))
soups = await asyncio.gather(*html_list)
所以我现在手动更改begloc_int和endloc_int
if cnt % 200 == 0:
switchIP()
但是我拥有的swithcIP()版本适用于常规Tor请求,而不是异步请求。
有人告诉我,我可以使用的是aiohttp-socks create_connection,但是我不知道该怎么做,而在github条目上查找并没有太多说明,因为没有示例。我认为create_connection需要在fetch函数中发生,但我根本不知道。
async def fetch(session,url):
# Somewhere in here stick in a create_connection
# with async_timeout.timeout(10):
async with session.get(url) as response:
return BeautifulSoup(await response.text(),"html.parser")
如果有人知道该怎么做,我将非常感谢您的帮助。
非常感谢您
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)