我试图使用BeautifulSoup从彭博社获得行业、行业和子行业的信息,使用以下代码:
import requests
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
headers = {'User-Agent': 'Mozilla/80.0'}
response = requests.get('https://www.bloomberg.com/profile/company/VRTU:US', headers = headers)
content = response.content
parser = BeautifulSoup(content, 'html.parser')
sector = parser.findAll('div', class_ = 'infoTableItemValue__e188b0cb')[1].text
industry = parser.findAll('div', class_ = 'infoTableItemValue__e188b0cb')[1].text
sub_industry = parser.findAll('div', class_ = 'infoTableItemValue__e188b0cb')[2].text这些代码只在单个股票提取时运行良好。但是,当我把它变成一个循环来提取股票列表时,彭博社会阻止我的IP,并返回被封锁的内容。
彭博-你是机器人吗?. document.getElementById("block_uuid").innerText =“块引用ID:”+ window._pxUuid;
即使我使用fake_useragent,彭博也封锁了我的IP。我有什么可以回避的,从彭博( Bloomberg )中提取股票清单吗?
发布于 2021-04-24 20:43:06
您需要使用代理,以便每个请求都是从不同的IP发出的。我发现最好的方法是你使用托尔。有一个python库柄可以用来控制tor。tor将做的是创建电路,以便您可以转发您的请求。该网站不会看到您的IP,但IP的托尔继电器。对于每一个请求,你都可以制造新的电路。这是来自不同IP的每个请求。我做过类似的使用selenium和Twitter。我销毁所有电路,然后为每个请求创建新的电路。
https://stackoverflow.com/questions/67242620
复制相似问题