Your Name 3 anos atrás
pai
commit
66128fdd72
1 arquivos alterados com 14 adições e 8 exclusões
  1. 14 8
      hhh/SEO/hhh_666_edges.py

+ 14 - 8
hhh/SEO/hhh_666_edges.py

@@ -89,18 +89,22 @@ def re_get_webdriver():
     time.sleep(4)
 
 #    options = webdriver.EdgeOptions()
-
-    driver = webdriver.Remote(
-        command_executor='http://127.0.0.1:6666/wd/hub')
-    driver.set_window_size(1400,1000)
+    try:
+        driver = webdriver.Remote(
+            command_executor='http://127.0.0.1:6666/wd/hub')
+        driver.set_window_size(1400,1000)
+    except:
+        return None
 
 def run_once(url):
     global driver
-    i=random.randint(0,13)
-#    if i==0 or driver is None:
-    if True:
+    i=random.randint(0,20)
+    if i<=3 or driver is None:
+#    if True:
         re_get_webdriver()
-    driver.get(url)
+    driver.execute_script('window.open("'+url+'","_blank");')
+#    driver.get(url)
+    driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
     time.sleep(1)
 
 
@@ -112,6 +116,7 @@ fpath=fpath.replace('hhh_666_edges.py','urls.csv')
 print(fpath)
 
 lst=[]
+
 fr=codecs.open(fpath,'r','utf-8')
 lines=fr.readlines()
 for l in lines:
@@ -119,6 +124,7 @@ for l in lines:
     lst.append('https://www.hhh.com.tw'+elmts[0])
 fr.close()
 
+#lst=['https://www.hhh.com.tw/columns/detail/3427/index.php']
     #for i in range(20):
 while True:
     l=random.choice(lst)