来自纳斯达克的刮痧表(初学者)

时间:2017-07-14 17:19:08

标签: python web-scraping beautifulsoup

url = https://www.nasdaqtrader.com/trader.aspx?id=TradeHalts

我正试图从上面的网址中抓取表格。但是,当我尝试使用beautifulsoup找到桌子时,我没有成功。我只是得到一个空列表。

请帮忙。

由于

import requests

from bs4 import BeautifulSoup

page = requests.get("https://www.nasdaqtrader.com/trader.aspx?id=TradeHalts")

soup = BeautifulSoup(page.text, "lxml")


item = soup.find(class_="genTable")


print(item)

1 个答案:

答案 0 :(得分:0)

我认为代码很清楚,但如果您有任何问题可以随意提问。

headers = {"Referer": "https://www.nasdaqtrader.com/trader.aspx?id=TradeHalts"}
data = {"id":2,"method":"BL_TradeHalt.GetTradeHalts","params":"[]","version":"1.1"}
url = "https://www.nasdaqtrader.com/RPCHandler.axd"
req = requests.post(url, json=data, headers=headers)
result = req.json()['result']
soup = BeautifulSoup(result, 'html.parser')
table = soup.find('table')