Your Name hace 3 años
padre
commit
78c1ed1bc3
Se han modificado 1 ficheros con 17 adiciones y 6 borrados
  1. 17 6
      hhh/SEO/hhh_777_edges.py

+ 17 - 6
hhh/SEO/hhh_777_edges.py

@@ -89,18 +89,27 @@ def re_get_webdriver():
     time.sleep(4)
 
 #    options = webdriver.EdgeOptions()
-
-    driver = webdriver.Remote(
-        command_executor='http://127.0.0.1:7777/wd/hub')
-    driver.set_window_size(1400,1000)
+    try:
+        driver = webdriver.Remote(
+            command_executor='http://127.0.0.1:7777/wd/hub')
+        driver.set_window_size(1400,1000)
+        return
+    except:
+        driver=None
+        return None
+    driver=None
 
 def run_once(url):
     global driver
-    i=random.randint(0,10)
+    i=random.randint(0,20)
     if i<=3 or driver is None:
 #    if True:
         re_get_webdriver()
-    driver.get(url)
+    if driver is None:
+        return
+    driver.execute_script('window.open("'+url+'","_blank");')
+#    driver.get(url)
+    driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
     time.sleep(1)
 
 
@@ -112,6 +121,7 @@ fpath=fpath.replace('hhh_777_edges.py','urls.csv')
 print(fpath)
 
 lst=[]
+
 fr=codecs.open(fpath,'r','utf-8')
 lines=fr.readlines()
 for l in lines:
@@ -119,6 +129,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)