我试图从中抓取的 URL 是一个实际的 URL:
https://www.lineups.com/nfl/player-stats/ezekiel-elliott
但是,如果我尝试请求此站点,我将被 (301) 重定向。如何强制访问此 URL?
我已经尝试过转:allow_redirects = False
url = "https://www.lineups.com/nfl/player-stats/Matt-Ryan"
r = requests.get(url, allow_redirects=False)
print(r.status_code, r.headers['Location']) # 301 /nfl/player-stats
print(r.url) # https://www.lineups.com/nfl/player-stats/Matt-Ryan
soup = BeautifulSoup(r.text, 'lxml')
print(soup)
永久移动。重定向到 /nfl/player-stats