未能从机场网站上抓取飞行数据表

2024-10-02 14:29:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直试图从新德里国际机场的网站上搜集国内航班的到港和离港数据。 我几乎什么都试过了,但无法提取数据。 当我运行代码时,它什么也不返回。我在另一个机场网站上尝试了类似的代码,但它成功了。 这是我写的代码。你知道吗

res = requests.get("https://m.newdelhiairport.in/live-flight- information-all.aspx?FLMode=A&FLType=D")
soup = BeautifulSoup(res.content,'html5lib')
table = soup.find_all('tbody',{'class':'arr_dep_table_body'})
print(table)

这是到网站:“https://m.newdelhiairport.in/live-flight-information-all.aspx?FLMode=A&FLType=D

A screenshot of the website


Tags: 数据代码inhttpsliveinformation网站table
1条回答
网友
1楼 · 发布于 2024-10-02 14:29:25

如前所述,您可以使用数据来源的替代URL。您需要添加标题。你知道吗

import requests
import pandas as pd

url = 'https://m.newdelhiairport.in/get-all-Fids-FlightInfo.aspx?FltType=D&FltWay=A&FltNum=&FltFrom=&rn=0.992638793938065'
re = requests.get(url, headers =  {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'})
df = pd.read_html(re.text)
print(df)

我从“网络”选项卡中提取了URL。我打开“网络”选项卡并重新加载页面,然后检查XHR web流量:

enter image description here

相关问题 更多 >