如何用python爬取数据_如何使用Python抓取实时流数据?

1586010002-jmsa.png

I was trying to scrape the number of flights for this webpage https://www.flightradar24.com/56.16,-49.51

The number is highlighted in the picture below:

Zvsmf.png

The number is updated every 8 seconds.

This is what I tried with BeautifulSoup:

import requests

from bs4 import BeautifulSoup

import time

r=requests.get("https://www.flightradar24.com/56.16,-49.51")

c=r.content

soup=BeautifulSoup(c,"html.parser")

value=soup.find_all("span",{"class":"choiceValue"})

print(value)

But that always returns 0:

[0]

View source also shows 0, so I understand why BeautifulSoup returns 0 too.

Anyone know any other method to get the current value?

解决方案

The problem with your approach is that the page first loads a view, then performs regular requests to refresh the page. If you look at the network tab in the developer console in Chrome (for example), you'll see the requests to https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=59.09,52.64,-58.77,-47.71&faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=7200&gliders=1&stats=1

The response is regular json:

{

"full_count": 11879,

"version": 4,

"afefdca": [

"A86AB5",

56.4288,

-56.0721,

233,

38000,

420,

"0000",

"T-F5M",

"B763",

"N641UA",

1473852497,

"LHR",

"ORD",

"UA929",

0,

0,

"UAL929",

0

],

...

"aff19d9": [

"A12F78",

56.3235,

-49.3597,

251,

36000,

436,

"0000",

"F-EST",

"B752",

"N176AA",

1473852497,

"DUB",

"JFK",

"AA291",

0,

0,

"AAL291",

0

],

"stats": {

"total": {

"ads-b": 8521,

"mlat": 2045,

"faa": 598,

"flarm": 152,

"estimated": 464

},

"visible": {

"ads-b": 0,

"mlat": 0,

"faa": 6,

"flarm": 0,

"estimated": 3

}

}

}

I'm not sure if this API is protected in any way, but it seems like I can access it without any issues using curl.

More info:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值