我正在尝试抓取此网站:https : //www.senate.gov/general/contact_information/senators_cfm.cfm
我的代码:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.senate.gov/general/contact_information/senators_cfm.cfm'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
print(soup)
问题在于它实际上并没有前往该站点。我从汤汁中得到的HTML根本与正确网页中的HTML完全不同。
我不确定从这里去哪里!任何和所有帮助将不胜感激。
这对我有用
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
}
r = requests.get(URL,headers=headers)
在这里找到信息-https: //towardsdatascience.com/5-strategies-to-write-unblock-able-web-scrapers-in-python-5e40c147bdaf
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句