1 回答
TA贡献1831条经验 获得超9个赞
您得到的原因在于,该页面是动态加载的,一旦页面本身加载,就会通过该页面呈现。NoneJavaScript
因此,我已经能够跟踪发送请求以获取它的来源。这可以通过浏览器在 下进行跟踪。tableJSXHRDeveloper-ToolsNetwork-Tab
否则,您可以使用它。我已经为您提供了这两种解决方案。selenium
import requests
import pandas as pd
json = {
"id": 2,
"method": "BL_TradeHalt.GetTradeHalts",
"params": "[]",
"version": "1.1"
}
headers = {
'Referer': 'https://www.nasdaqtrader.com/trader.aspx?id=TradeHalts'
}
r = requests.post(
"https://www.nasdaqtrader.com/RPCHandler.axd", json=json, headers=headers).json()
df = pd.read_html(r["result"])[0]
df.to_csv("table1.csv", index=False)
输出:在线查看
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
import pandas as pd
options = Options()
options.add_argument('--headless')
driver = webdriver.Firefox(options=options)
driver.get(
"https://www.nasdaqtrader.com/trader.aspx?id=TradeHalts")
df = pd.read_html(driver.page_source)[2]
# print(df)
df.to_csv("table.csv", index=False)
driver.quit()
输出:在线查看
添加回答
举报