[英]Scraping webpage using BeautifulSoup
我正在嘗試抓取這個網站: 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)
問題是它實際上並沒有進入該站點。 我在湯 var 中得到的 HTML 根本不是正確網頁中的 HTML 。
我不確定 go 從這里到哪里。 任何和所有的幫助將不勝感激。
這對我有用
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 使用 python 請求模塊時出錯
試試看:
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.