forked from nilshellerhoff/warthunder-replay-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_vehicles.py
48 lines (36 loc) · 1.2 KB
/
get_vehicles.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import requests
import sys
from bs4 import BeautifulSoup
import json
def _parse_page(page):
soup = BeautifulSoup(page, "html.parser")
vehicle_tags = soup.find_all("div", {"class": "tree-item"})
vehicles = []
for vehicle in vehicle_tags:
image = vehicle.find("div", {"class": "tree-item-img"}).find("img")["src"]
slug = image.split('/')[-1].split('.')[0]
name = vehicle.find("span", {"class": "tree-item-text-scroll"}).text
link = vehicle.find("a")["href"]
if "http" not in link: link = "https://wiki.warthunder.com" + link
vehicles.append({
"slug": slug,
"name": name,
"link": link,
"image": image
})
return vehicles
def get_vehicles(url):
"""
get all the vehicles listed on a wiki page (e.g. https://wiki.warthunder.com/Category:Germany_aircraft))
"""
page = requests.get(url).text
return _parse_page(page)
def main():
if len(sys.argv) < 2:
print("Usage: python aircraft_wiki.py <aircraft_wiki_url>")
sys.exit(1)
url = sys.argv[1]
vehicles = get_vehicles(url)
print(json.dumps(vehicles, indent=4))
if __name__ == "__main__":
main()