jared 3 anos atrás
pai
commit
295a356f5b
2 arquivos alterados com 40 adições e 4 exclusões
  1. 6 0
      linux_loop.sh
  2. 34 4
      shop_item_list.py

+ 6 - 0
linux_loop.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+while :
+do
+    python swire_shop_item_list.py
+	sleep 1
+done

+ 34 - 4
shop_item_list.py

@@ -84,7 +84,7 @@ def get_url_list(driver):
     #         pass
 
     # wait = WebDriverWait(driver, 30)
-    # try:
+    # try:地圖移動時更新結果
     #     wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="ppdPk-Ej1Yeb-LgbsSe-tJiF1e"]')))
     # except selenium.common.exceptions.TimeoutException:
     #     traceback.print_exc()
@@ -169,6 +169,27 @@ def get_lon_lat_list(db, keyword):
 
     return lst
 
+def parsing_js(orig):
+    content=""
+    lines=orig.split('\n')
+    for l in lines:
+        newl=l.replace('\\"','"')
+        content+=newl
+    result=re.search(r'\[\["',content)
+    content_begin=result.start()
+
+    result=re.search(r'\]\]"',content)
+    content_end=result.end()
+    jscontent=content[content_begin:content_end-1]
+    jsobj=json.loads(jscontent)
+    print()
+    for x in jsobj[0][1][1:]:
+        print(x[14][11])
+        print(x[14][10])
+        print(x[14][2])
+        print(x[14][78])
+
+
 
 def main():
     global chrome_window
@@ -226,9 +247,18 @@ def main():
                             print('parsing js:')
                             resp = brotli.decompress(request.response.body)
                             jstext=resp.decode('utf-8')
-                            print(jstext)
-                            jsobj=json.loads(jstext)
-                            print(jsobj)
+                            parsing_js(jstext)
+
+
+
+#                            import codecs
+#                            fw=codecs.open('c:/tmp/ot.json','w','utf-8')
+#                            fw.write(jstext)
+#                            fw.close()
+#                            print(jstext)
+#                            time.sleep(9999)
+#                            jsobj=json.loads(jstext)
+#                            print(jsobj)
 #                sys.exit()