Skip to content

Commit 50c4bdf

Browse files
committed
Headers
1 parent 044a3bf commit 50c4bdf

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

scrape_airline_routes.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010

1111
if __name__ == "__main__":
1212

13+
1314
print("Fetching airports list...")
15+
16+
airports_headers = {
17+
"Accept": "application/json",
18+
"Origin": "https://www.flightsfrom.com",
19+
"Referer": "https://www.flightsfrom.com/"
20+
}
1421
response = requests.get(
15-
"https://www.flightsfrom.com/airports", impersonate="chrome"
22+
"https://www.flightsfrom.com/airports", impersonate="chrome", headers=airports_headers
1623
)
1724
try:
1825
airports_json = json.loads(response.content)
@@ -33,8 +40,15 @@
3340

3441
while True:
3542
try:
43+
destinations_headers = {
44+
"Accept": "text/html",
45+
"Origin": "https://www.flightsfrom.com",
46+
"Referer": "https://www.flightsfrom.com/"
47+
}
3648
response = requests.get(
37-
"https://www.flightsfrom.com/%s/destinations" % iata, impersonate="chrome"
49+
"https://www.flightsfrom.com/%s/destinations" % iata,
50+
impersonate="chrome",
51+
headers=destinations_headers
3852
)
3953
root = lxml.html.document_fromstring(response.content)
4054
metadata_nodes = root.xpath('//script[contains(., "window.airport")]')

0 commit comments

Comments
 (0)