无法从机场网站上获取航班数据表

时间:2018-12-13 05:11:26

标签: python web-scraping beautifulsoup

我一直在尝试从新德里国际机场的网站上抓取国内航班的到达和起飞数据。 我已经尝试了几乎所有内容,但无法提取数据。 当我运行代码时,它什么也没有返回。我在另一个机场网站上尝试了类似的代码,但是它起作用了。 这是我写的代码。

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

1 个答案:

答案 0 :(得分:1)

如前所述,您可以使用其他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