我正在尝试抓取此网站: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)
DUPLICATE HTTP 503 Error while using python requests module
尝试:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.senate.gov/general/contact_information/senators_cfm.cfm'
page = requests.post(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
print(soup)