-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.py
28 lines (26 loc) · 1.06 KB
/
scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
from datetime import datetime
from bs4 import BeautifulSoup
headers = {
"accept-encoding": "gzip, br",
"accept-language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
"cache-control": "max-age=0",
"origin": "https://www.flightradar24.com",
"referer": "https://www.flightradar24.com/",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"user-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
}
def getFlights(registration:str, day):
flights = []
res = requests.get(f"https://www.flightradar24.com/data/aircraft/{registration}#", headers=headers)
res.raise_for_status()
soup = BeautifulSoup(res.content, "html.parser")
playback_links = soup.find_all('a', title="Show playback of flight")
for link in playback_links:
timestamp = int(link.get('data-timestamp'))
date = datetime.fromtimestamp(timestamp).date()
if date == day:
flights.append(link.get('data-flight-hex'))
return flights