uc_whoogle.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import undetected_chromedriver as uc
  2. import time
  3. import libads
  4. import sys
  5. import random
  6. from selenium import webdriver
  7. import time
  8. from selenium.webdriver.common.by import By
  9. from selenium.webdriver.common.keys import Keys
  10. import os
  11. import pymysql
  12. pymysql.install_as_MySQLdb()
  13. if os.name == 'nt':
  14. driver = uc.Chrome(headless=False)
  15. else:
  16. driver = uc.Chrome(headless=True,driver_executable_path='/usr/bin/chromedriver')
  17. kw=''
  18. region='tw'
  19. language='zh-TW'
  20. db3=libads.get_db(libads.DB_OPENLOG)
  21. cursor=db3.query('select kw from search_keywords order by rand() limit 1')
  22. kw=list(cursor)[0]
  23. #randomstr=['印度內觀課程','呂秀金內觀課程','呂秀金印度酥油','印度聖境心靈','算力傳媒','呂秀金印度心靈課程','呂秀金2025創造績效課程','國喬東南亞銷售','幸福空間','hhh裝潢費用試算','國喬尼龍生產','生成式seo genseo','活在真心的國度','森林大學出版','超越生命的愛','呂秀金覺醒']
  24. #kw=random.choice(randomstr)
  25. print(kw)
  26. driver.get(f'http://192.168.192.247:5000/')
  27. #https://google.com?gl=tw&hl=zh-TW&num=100
  28. time.sleep(3)
  29. elmt=driver.find_element(By.XPATH,'//button[@id="config-collapsible"]')
  30. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  31. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  32. time.sleep(2)
  33. elmt=driver.find_element(By.XPATH,'//input[@name="tor"]')
  34. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  35. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  36. time.sleep(1)
  37. elmt=driver.find_element(By.XPATH,'//input[@value="Apply"]')
  38. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  39. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  40. time.sleep(1)
  41. #webdriver.ActionChains(driver).move_to_element(elmt).perform()
  42. #webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  43. elmt=driver.find_element(By.XPATH,'//input[@id="search-bar"]')
  44. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  45. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  46. elmt.send_keys(kw)
  47. elmt.send_keys(Keys.ENTER)
  48. time.sleep(5)
  49. elmts=driver.find_elements(By.XPATH,'//div[@class="ezO2md"]')
  50. for elmt in elmts:
  51. print(elmt.text)