import requests
from bs4 import BeautifulSoup
import json
import threading
def scrape_page(page):
text = requests.get("https://airportcode.bmcx.com/" + str(page) + "__airportcode/")
res = text.text
soup = BeautifulSoup(res, features="lxml")
arr = soup.findAll(name="table")[0].findAll(name="tr")
for i in arr[2:]:
t = i.findAll(name="td")
v = ""
if t[3].string is not None:
v = t[3].string
with lock:
dic[t[1].string] = v
dic = {}
lock = threading.Lock()
n = 290
threads = []
for i in range(1, n):
thread = threading.Thread(target=scrape_page, args=(i,))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
s = json.dumps(dic, ensure_ascii=False)
print(s)
with open('json.json', 'w') as f:
f.write(s)
世界机场三字码
最新推荐文章于 2025-05-14 21:45:37 发布