【问题标题】:Scraping bond data from Wall Street Journal using Beautiful Soup使用 Beautiful Soup 从华尔街日报抓取债券数据
【发布时间】:2020-09-04 11:53:05
【问题描述】:

我正在尝试使用 Beautiful Soup 从 WSJ 市场页面抓取一些数据,但总是收到 Status Code=404 Page not found 消息。我的代码在其他网站上运行良好,所以出了什么问题?

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)

【问题讨论】:

  • 我猜你必须发送一些标头,例如 user-agent
  • 我该怎么做?
  • @SteveB 按照我下面的代码。我想,它会帮助你

标签: python beautifulsoup python-requests


【解决方案1】:

您需要添加headers。你可以试试:

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)

【讨论】:

  • 酷,行得通。我想这可以防止机器人。谢谢
猜你喜欢
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
  • 2020-10-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多