Explorar o código

try new method

Jason hai 1 ano
pai
achega
5d05ac5466
Modificáronse 2 ficheiros con 122 adicións e 0 borrados
  1. 97 0
      website_clickjobs/type-R/_clickjob.py
  2. 25 0
      website_clickjobs/type-R/tcd.py

+ 97 - 0
website_clickjobs/type-R/_clickjob.py

@@ -0,0 +1,97 @@
+#import redis
+import time
+import traceback
+#import json
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+import time
+import os
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support import expected_conditions as EC
+import dataset
+
+import json
+import random
+import time
+import sys
+import codecs
+import random
+import os
+import time
+from userAgentRandomizer import userAgents
+
+driver=None
+
+def re_get_webdriver():
+    global driver
+    result=[]
+    if driver is not None:
+        driver.quit()
+       # os.system('killall chrome')
+        print('Driver Closed')
+        driver=None
+    try:
+        ua = userAgents()
+
+        user_agent = ua.random()        
+
+        options = webdriver.ChromeOptions()
+
+
+        mobile_emulation = {
+            "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
+            "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
+        options.add_experimental_option("mobileEmulation", mobile_emulation)
+
+        options.add_argument("--no-sandbox")
+        options.add_argument("--disable-dev-shm-usage")
+        options.add_argument("--headless")
+
+#        print(user_agent)
+#        options.add_argument("--user-agent=" +user_agent)
+        options.add_argument("--incognito")
+        driver=None
+        try:
+            driver = webdriver.Chrome(options=options)
+        except:
+            if driver is not None:
+                driver.quit()
+#            driver.quit()
+#            os.system('pkill -f ')
+            print('kill %d'%os.getpid())
+            driver = None
+            #os.system('killall chrome')
+            #os.system('kill %d' % os.getpid())
+            
+            #sys.exit()
+            return
+#        driver.set_window_size(1400,1000)
+        return
+    except:
+        import traceback
+        traceback.print_exc()
+        driver=None
+        return None
+
+def run_once(url):
+    global driver
+    i=random.randint(0,7)
+    if i==0 or driver is None:
+        time.sleep(8)
+        re_get_webdriver()
+    if driver is None:
+        return
+    try:
+        
+        #time.sleep(0.5)
+        driver.execute_script('window.open("'+url+'","_blank");')
+        driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
+        time.sleep(0.5)
+        print(url)
+        #driver.quit()
+    except Exception as e:
+
+        print('exception:',e)
+
+

+ 25 - 0
website_clickjobs/type-R/tcd.py

@@ -0,0 +1,25 @@
+from _clickjob import *
+
+def resetlst():
+    return ['https://www.tcdream.taichung.gov.tw/']
+
+lst=[]
+
+#db = dataset.connect('DATABASE LINK HERE')
+
+lst=resetlst()
+
+while True:
+    try:
+        l=random.choice(lst)
+       # print(l)
+        run_once(l)
+        
+        x=random.randint(0,5)
+        y=random.randint(0,6)
+        if x==y:
+            lst=resetlst()
+    except:
+        import time
+        time.sleep(5)
+        print('ERROR')