|
@@ -10,6 +10,19 @@ import urllib
|
|
|
import argparse
|
|
|
import schedule
|
|
|
|
|
|
+import logging
|
|
|
+import sys
|
|
|
+from logging.handlers import SysLogHandler
|
|
|
+import socket
|
|
|
+
|
|
|
+_LOG_SERVER = ('hhh.ptt.cx', 514)
|
|
|
+logger = logging.getLogger('clickbot_100')
|
|
|
+handler1 = SysLogHandler(address=_LOG_SERVER,socktype=socket.SOCK_DGRAM)
|
|
|
+logger.addHandler(handler1)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def restart_browser():
|
|
|
options = webdriver.ChromeOptions()
|
|
|
driver=webdriver.Chrome(options=options)
|
|
@@ -20,12 +33,14 @@ def restart_browser():
|
|
|
def process_one():
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
|
|
|
lst=[]
|
|
|
+ table=db['save_result']
|
|
|
cursor=db.query('select term from selected_kw where client="清原"')
|
|
|
for c in cursor:
|
|
|
lst.append(c['term'])
|
|
|
|
|
|
term=random.choice(lst)
|
|
|
print(term)
|
|
|
+ logger.debug('[clickbot_100]['+term+']')
|
|
|
driver=restart_browser()
|
|
|
escaped_search_term=urllib.parse.quote(term)
|
|
|
googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(escaped_search_term, 100,'zh-TW')
|
|
@@ -36,18 +51,27 @@ def process_one():
|
|
|
|
|
|
elmts=driver.find_elements_by_xpath("//div[@class='yuRUbf']/a")
|
|
|
|
|
|
+ clickelmt=None
|
|
|
+ cnt=1
|
|
|
for elmt in elmts:
|
|
|
try:
|
|
|
href=elmt.get_attribute('href')
|
|
|
if 'taroboba-yuan.com' in href:
|
|
|
- webdriver.ActionChains(driver).move_to_element(elmt).perform()
|
|
|
- webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
|
|
|
+ clickelmt=elmt
|
|
|
+ logger.debug('[clickbot_100]['+term+']['+str(cnt)+']')
|
|
|
+
|
|
|
print(href)
|
|
|
print(elmt.text)
|
|
|
- break
|
|
|
+ table.insert({'title':elmt.text,'url':href,'keyword':term,'dt':datetime.datetime.now(),'num':cnt})
|
|
|
+ cnt+=1
|
|
|
except:
|
|
|
print('href2 exception')
|
|
|
traceback.print_exc()
|
|
|
+ if clickelmt:
|
|
|
+ webdriver.ActionChains(driver).move_to_element(clickelmt).perform()
|
|
|
+ webdriver.ActionChains(driver).move_to_element(clickelmt).click().perform()
|
|
|
+
|
|
|
+
|
|
|
driver.quit()
|
|
|
|
|
|
process_one()
|
|
@@ -58,7 +82,7 @@ args = parser.parse_args()
|
|
|
|
|
|
if args.loop:
|
|
|
|
|
|
- schedule.every(5).minutes.do(process_one)
|
|
|
+ schedule.every(6).minutes.do(process_one)
|
|
|
|
|
|
while True:
|
|
|
schedule.run_pending()
|