Jason 1 år sedan
förälder
incheckning
4081c8ff66
2 ändrade filer med 20 tillägg och 17 borttagningar
  1. 13 9
      website_clickjobs/type-V/_execute.py
  2. 7 8
      website_clickjobs/type-V/c1.py

+ 13 - 9
website_clickjobs/type-V/_execute.py

@@ -10,7 +10,7 @@ import pandas as pd
 from PIL import Image
 import dataset
 from datetime import datetime
-from random import randint
+from random import randint, choice
 
 #from setting import rua
 
@@ -31,7 +31,7 @@ def restart_browser():
 
 resultdict={'搜尋詞':[],'網域':[],'結果標題':[],'結果網址':[],'結果名次':[]}
 
-def process_one(term, target, n, sr, se):
+def process_one(term, tgt, n, sr, se):
     try:
         print(term)
 
@@ -57,6 +57,7 @@ def process_one(term, target, n, sr, se):
         resultttl = "X"
         resultlink = "X"
         resultrank = "X"
+        target = []
         
         for elmt in elmts:
             try:
@@ -65,16 +66,14 @@ def process_one(term, target, n, sr, se):
                 datadict['結果標題'].append(elmt.text)
                 datadict['結果網址'].append(href)
                 datadict['結果名次'].append(str(cnt))
-                if (n==1 or n==2) and target in href and found==0:
+
+                if (n==1 or n==2) and href.split('?')[0] in tgt:
                     found=1
                     clickelmt = elmt
                     resultrank = str(cnt)
                     resultlink = href
                     resultttl = elmt.text
-                    print("Target domain found")
-                    print(resultttl)
-                    print(resultlink)
-                    print(resultrank)
+                    target.append([clickelmt, resultlink, resultrank, resultttl])
                 cnt+=1
             except:
                 print('href2 exception')
@@ -85,10 +84,15 @@ def process_one(term, target, n, sr, se):
             # driver.quit()
             # sys.exit()
         
-        if n==2 and found==1:
+        if n==2 and len(target)!=0:
+            selection = choice(target)
+            clickelmt = selection[0]
             webdriver.ActionChains(driver).move_to_element(clickelmt).perform()
             webdriver.ActionChains(driver).move_to_element(clickelmt).click().perform()
             print("Clicked")
+            print(selection[3])
+            print(selection[1])
+            print(selection[2])
             time_stamp = datetime.fromtimestamp(time.time())
             time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
             if se==1:
@@ -96,7 +100,7 @@ def process_one(term, target, n, sr, se):
             else:
                 table=db['general_log']
             
-            table.insert({'ranking':resultrank,'kw':term,'results':count,'url':resultlink,'title':resultttl,'dt':time_stamp})
+            table.insert({'kw':term,'results':count,'url':selection[1],'ranking':selection[2],'title':selection[3],'dt':time_stamp})
             time.sleep(30)
         
         driver.quit()

+ 7 - 8
website_clickjobs/type-V/c1.py

@@ -1,22 +1,21 @@
 #coding=utf-8
 from _execute import *
-import random
 
 def pickvideo():
-    n = random.randint(0,3)
+    n = randint(0,3)
     if n==0:
         term = "信義房屋"
-        whitelist = ['https://hr.sinyi.com.tw/','https://www.youtube.com/channel/UCU76s7FGtDvDta2mf2Zdn4Q','https://csr.sinyi.com.tw/client/innovation.php','https://www.youtube.com/user/sinyicity','https://www.sinyi.com.tw/aboutsinyi/aboutsinyi_publish','https://csr.sinyi.com.tw/news/anti-pandemic.php','https://events.sinyi.com.tw/20190828_webintro/','https://csr.sinyi.com.tw/society/charity.php','https://www.ncscre.nccu.edu.tw/node/638','https://www.youtube.com/channel/UCV-0ttUE0Z-BTuBcwvQNjgQ','https://www.youtube.com/playlist?list=PLftfxwJcQDUCL8v2oB_jHWHue4I6vHyBz','https://www.youtube.com/watch?v=mlqY5X2oTuk','https://hr.sinyi.com.tw/events/1/?utm_source=Facebook_hr&utm_medium=display&utm_term=web&utm_content=video','https://events.sinyi.com.tw/tvc2018-forhome/']
+        whitelist = ['https://www.youtube.com/channel/UCU76s7FGtDvDta2mf2Zdn4Q','https://www.youtube.com/user/sinyicity','https://www.sinyi.com.tw/aboutsinyi/aboutsinyi_publish','https://events.sinyi.com.tw/20190828_webintro/','https://csr.sinyi.com.tw/','https://csr.sinyi.com.tw/society/index.php','https://csr.sinyi.com.tw/governance/index.php','https://www.youtube.com/channel/UCV-0ttUE0Z-BTuBcwvQNjgQ','https://hr.sinyi.com.tw/events/1/','https://events.sinyi.com.tw/tvc2018-forhome/','https://www.ncscre.nccu.edu.tw/node/638','https://www.youtube.com/playlist?list=PLftfxwJcQDUCL8v2oB_jHWHue4I6vHyBz','https://www.facebook.com/SinyiRealtyInc.HR/?locale=zh_TW','https://csr.sinyi.com.tw/society/charity.php','https://csr.sinyi.com.tw/society/community.php','https://www.youtube.com/watch?v=iWOHUiGwnPE']
     if n==1:
         term = "信義 房屋"
-        whitelist = ['https://hr.sinyi.com.tw/','https://www.youtube.com/channel/UCU76s7FGtDvDta2mf2Zdn4Q','https://csr.sinyi.com.tw/client/innovation.php','https://www.youtube.com/user/sinyicity','https://www.sinyi.com.tw/aboutsinyi/aboutsinyi_publish','https://csr.sinyi.com.tw/news/anti-pandemic.php','https://events.sinyi.com.tw/20190828_webintro/','https://csr.sinyi.com.tw/society/charity.php','https://www.ncscre.nccu.edu.tw/node/638','https://www.youtube.com/channel/UCV-0ttUE0Z-BTuBcwvQNjgQ','https://www.youtube.com/playlist?list=PLftfxwJcQDUCL8v2oB_jHWHue4I6vHyBz','https://hr.sinyi.com.tw/events/1/?utm_source=Facebook_hr&utm_medium=display&utm_term=web&utm_content=video','https://events.sinyi.com.tw/tvc2018-forhome/','https://www.youtube.com/watch?v=rGQqegE8rbc','https://csr.sinyi.com.tw/society/community.php']
+        whitelist = ['https://www.youtube.com/channel/UCU76s7FGtDvDta2mf2Zdn4Q','https://www.youtube.com/user/sinyicity','https://www.sinyi.com.tw/aboutsinyi/aboutsinyi_publish','https://csr.sinyi.com.tw/','https://events.sinyi.com.tw/20190828_webintro/','https://csr.sinyi.com.tw/governance/index.php','https://www.facebook.com/profile.php?id=100063685940694','https://www.facebook.com/SinyiRealtyInc.HR/?locale=zh_TW','https://csr.sinyi.com.tw/society/index.php','https://hr.sinyi.com.tw/events/1/','https://events.sinyi.com.tw/tvc2018-forhome/','https://www.youtube.com/channel/UCV-0ttUE0Z-BTuBcwvQNjgQ','https://www.youtube.com/playlist?list=PLftfxwJcQDUCL8v2oB_jHWHue4I6vHyBz','https://www.youtube.com/watch?v=A5GuB3Enw9U']
     if n==2:
         term = "信義房仲"
-        whitelist = ['https://www.youtube.com/watch?v=1OxZNuwlUOk','https://www.youtube.com/watch?v=uOsZiIhyxVM','https://www.youtube.com/watch?v=juJTjzi4DV0','https://www.sinyinews.com.tw/sinyipedia/buyarticle/337','https://www.youtube.com/channel/UCU76s7FGtDvDta2mf2Zdn4Q','https://hr.sinyi.com.tw/events/1/?utm_source=Facebook_hr&utm_medium=display&utm_term=web&utm_content=video','https://www.youtube.com/watch?v=tbdpEt65LRI','https://www.youtube.com/user/sinyicity','https://www.youtube.com/watch?v=iWOHUiGwnPE','https://csr.sinyi.com.tw/client/innovation.php','https://hr.sinyi.com.tw/events/tvc/','https://www.youtube.com/watch?v=nj1mTUG8yJo','https://www.sinyinews.com.tw/s_channel/videodetail/59','https://www.youtube.com/watch?v=A5GuB3Enw9U','https://www.mirrormedia.mg/story/20230712cnt001/']
+        whitelist = ['https://www.youtube.com/watch?v=uOsZiIhyxVM','https://www.youtube.com/channel/UCU76s7FGtDvDta2mf2Zdn4Q','https://www.sinyinews.com.tw/sinyipedia/buyarticle/337','https://www.youtube.com/watch?v=68PyCj3iKPM','https://www.youtube.com/watch?v=1OxZNuwlUOk','https://www.youtube.com/watch?v=juJTjzi4DV0','https://www.youtube.com/user/sinyicity','https://hr.sinyi.com.tw/events/tvc/','https://www.youtube.com/watch?v=iWOHUiGwnPE','https://www.sinyinews.com.tw/s_channel/videodetail/60','https://hr.sinyi.com.tw/events/1/','https://sinyipodcast.com.tw/article/news/trend/44','https://www.youtube.com/watch?v=tbdpEt65LRI','https://www.youtube.com/watch?v=A5GuB3Enw9U','https://www.facebook.com/SinyiRealtyInc.HR/?locale=zh_TW','https://www.youtube.com/watch?v=_81dZcHI3_Q']
     if n==3:
         term = "信義 房仲"
-        whitelist = ['https://www.youtube.com/watch?v=1OxZNuwlUOk','https://www.youtube.com/watch?v=uOsZiIhyxVM','https://www.youtube.com/watch?v=juJTjzi4DV0','https://www.sinyinews.com.tw/sinyipedia/buyarticle/337','https://hr.sinyi.com.tw/events/1/?utm_source=Facebook_hr&utm_medium=display&utm_term=web&utm_content=video','https://www.youtube.com/watch?v=tbdpEt65LRI','https://hr.sinyi.com.tw/events/tvc/','https://www.sinyinews.com.tw/s_channel/videodetail/58','https://sinyipodcast.com.tw/article/news/trend/44','https://www.youtube.com/user/sinyicity','https://www.youtube.com/watch?v=iWOHUiGwnPE','https://www.youtube.com/channel/UCU76s7FGtDvDta2mf2Zdn4Q','https://www.sinyinews.com.tw/s_channel/videodetail/59']
-    return term, random.choice(whitelist)
+        whitelist = ['https://www.youtube.com/watch?v=uOsZiIhyxVM','https://www.sinyinews.com.tw/sinyipedia/buyarticle/337','https://www.youtube.com/watch?v=68PyCj3iKPM','https://www.youtube.com/watch?v=1OxZNuwlUOk','https://www.youtube.com/watch?v=juJTjzi4DV0','https://sinyipodcast.com.tw/article/news/trend/44','https://www.youtube.com/channel/UCU76s7FGtDvDta2mf2Zdn4Q','https://www.sinyinews.com.tw/s_channel/videodetail/60','https://hr.sinyi.com.tw/events/1/','https://hr.sinyi.com.tw/events/tvc/','https://www.sinyinews.com.tw/s_channel/videodetail/58','https://www.youtube.com/watch?v=JzH-XYkEjgg','https://sinyipodcast.com.tw/article/news/trend/46','https://www.youtube.com/watch?v=tbdpEt65LRI','https://www.youtube.com/watch?v=70u509rtnHc']
+    return term, whitelist
 
 termlist = ["信義房屋","信義 房屋","信義房仲","信義 房仲"]
 
@@ -30,6 +29,6 @@ if clickvideo == 1 or clickvideo == 2:
     while True:
         kw, target = pickvideo()
         process_one(kw, target, clickvideo, savefile, sec)
-        time.sleep(10)
+        time.sleep(7)
 elif savefile == 1:
     execute(termlist, "", clickvideo, savefile, sec)