[英]Scraping bond data from Wall Street Journal using Beautiful Soup
I'm trying to scrape some data from the WSJ markets page using Beautiful Soup but always get Status Code=404 Page not found message.我正在尝试使用 Beautiful Soup 从 WSJ 市场页面中抓取一些数据,但总是得到 Status Code=404 Page not found 消息。 My code works fine on other websites so what's going wrong?我的代码在其他网站上运行良好,所以出了什么问题?
import requests
from bs4 import BeautifulSoup
url='https://www.wsj.com/market-data/quotes/bond/BX/TMBMKJP-10Y?mod=md_bond_govt_bonds_quote'
page=requests.get(url)
soup=BeautifulSoup(page.content,'html.parser')
print('Page status code',page.status_code)
You need to add headers
.您需要添加headers
。 You can try it:你可以试试:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0 '}
url='https://www.wsj.com/market-data/quotes/bond/BX/TMBMKJP-10Y?mod=md_bond_govt_bonds_quote'
page=requests.get(url, headers=headers)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.