Explorar o código

获取机场三字码

郑毅 hai 4 meses
pai
achega
aa9a1c4d33
Modificáronse 4 ficheiros con 48 adicións e 7 borrados
  1. 15 0
      .vscode/launch.json
  2. 33 7
      __main__.py
  3. 0 0
      json.json
  4. 0 0
      json1.json

+ 15 - 0
.vscode/launch.json

@@ -0,0 +1,15 @@
+{
+    // 使用 IntelliSense 了解相关属性。 
+    // 悬停以查看现有属性的描述。
+    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Python 调试程序: 当前文件",
+            "type": "debugpy",
+            "request": "launch",
+            "program": "${file}",
+            "console": "integratedTerminal"
+        }
+    ]
+}

+ 33 - 7
__main__.py

@@ -1,13 +1,39 @@
-import re
-import time
-
+import requests
+import json
+from bs4 import BeautifulSoup
 
 def main():
     # print('[{}] Hello world!'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))))
-    str = '188888'
-    n = len(str)
-    new_str = '****' if len(str) <= 4 else str[0:int(n/3)] + '****' + str[int(n*2/3):]
-    print(new_str)
+    # str = '188888'
+    # n = len(str)
+    # new_str = '****' if len(str) <= 4 else str[0:int(n/3)] + '****' + str[int(n*2/3):]
+    # print(new_str)
+
+    result = []
+    n = 290
+    for i in range(1, n):
+        page = i
+        text = requests.get("https://airportcode.bmcx.com/" + str(page) + "__airportcode/")
+        res = text.text
+        soup = BeautifulSoup(res, features="html.parser")
+        arr = soup.find_all(name = "table")[1].find_all(name = "tr")
+        for i in arr[2:]:
+            t = i.find_all(name = "td")
+            href = t[0].find(name = "a").attrs.get("href")
+            if href != None:
+                sub_text = requests.get("https://airportcode.bmcx.com" + href)
+                sub_res = sub_text.text
+                sub_soup = BeautifulSoup(sub_res, features="html.parser")
+                sub_arr = sub_soup.find_all(name = "table")[1].find_all(name = "tr")
+                item = {}
+                for j in sub_arr[2:]:
+                    sub_t = j.find_all(name = "td")
+                    item[sub_t[0].string] = sub_t[1].string
+                result.append(item)
+    s = json.dumps(result, ensure_ascii=False)
+    # print(s)
+    with open('json.json', 'w') as f:
+        f.write(s)
 
 
 # 程序入口

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
json.json


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
json1.json


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio