我想在请求后用BeautifulSoup
刮取此页,但我找不到table
代码
headers = {"Referer": "https://www.atptour.com/en/scores/results-archive",
'User-Agent': 'my-user-agent'
}
url = 'https://www.atptour.com/en/scores/results-archive?year=2016'
page = requests.get(url, headers=headers)
print(page)
soup = BeautifulSoup(page.text, 'html.parser')
table = soup.find('table', class_="results-archive-table mega-table")
print(table)
输出<Response [403]>
{
我使用
scrapy-selenium
和selenium stealth
得到Response [200]
代码:
输出:
这些网站受到Cloudflare的保护,并希望在访问网站时启用javascript,就像真正的浏览器一样,
requests
库无法执行。因此,您可以尝试使用Selenium
另一件事我注意到在
headless
模式中使用Selenium
会抛出captcha,但non-headless
有效。最后,您可以使用Beautifusoup
进行解析试试这个:
看看答案:
也许你必须在你的请求中添加一些标题
相关问题 更多 >
编程相关推荐