4 次代碼提交 b1c07b0aeb ... aa9a1c4d33

作者 SHA1 備註 提交日期
  郑毅 aa9a1c4d33 获取机场三字码 4 月之前
  郑毅 eefa699b17 update 6 月之前
  郑毅 f3fc8b7fe9 update 6 月之前
  郑毅 c098f1ec25 update 6 月之前
共有 4 個文件被更改,包括 49 次插入3 次删除
  1. 15 0
      .vscode/launch.json
  2. 34 3
      __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"
+        }
+    ]
+}

+ 34 - 3
__main__.py

@@ -1,8 +1,39 @@
-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()))))
+    # 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)
+
+    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)
 
 
 # 程序入口

File diff suppressed because it is too large
+ 0 - 0
json.json


File diff suppressed because it is too large
+ 0 - 0
json1.json


Some files were not shown because too many files changed in this diff