擅长:python、mysql、java
<p>因此,根据@Andre发现的情况,我编写了以下代码:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
import time
def get_count():
url = "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"
# Request with fake header, otherwise you will get an 403 HTTP error
r = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
# Parse the JSON
data = r.json()
counter = 0
# Iterate over the elements to get the number of total flights
for element in data["stats"]["total"]:
counter += data["stats"]["total"][element]
return counter
while True:
print(get_count())
time.sleep(8)
</code></pre>
<p>代码应该是自我解释的,它所做的一切就是每8秒打印一次实际的航班计数:)</p>
<p><strong>注意:</strong><em>这些值与网站上的值相似,但不相同。这是因为Python脚本和网站不太可能同时发送请求。如果你想得到更准确的结果,例如每4秒就要发出一个请求。</em></p>
<p>你想用什么就用什么,扩展什么。希望这有帮助!</p>