chrometest.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. from selenium import webdriver
  2. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  3. import time
  4. import os
  5. import datetime
  6. import urllib.parse
  7. from selenium.webdriver.support.ui import WebDriverWait
  8. from selenium.webdriver.common.by import By
  9. from selenium.webdriver.support import expected_conditions as EC
  10. import codecs
  11. from selenium.webdriver.common.by import By
  12. import random
  13. from bs4 import BeautifulSoup
  14. import requests
  15. import time
  16. import rpyc
  17. import sys
  18. import docker
  19. import googlesearch
  20. import codecs
  21. import sys
  22. import time
  23. import dataset
  24. import os
  25. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
  26. #cursor=db.query('SELECT kw FROM hhh.hhh_contentgap_serp where ranking is not null;')
  27. #cursor=db.query('SELECT kw FROM hhh.hhh_contentgap_serp where kw not in (select distinct kw from hhh_contentgap_serp where id >= 155)')
  28. kwlst={}
  29. #for c in cursor:
  30. # kwlst[c['kw']]=1
  31. table=db['hhh_contentgap_serp']
  32. curdir=os.path.realpath('.')
  33. #fr=codecs.open(curdir+os.sep+'contentgap.txt','r','utf-8')
  34. #fr=codecs.open(curdir+os.sep+'hhh\\seo\\contentgap.txt','r','utf-8')
  35. fr=codecs.open('C:\\gitlab\\kw_tools\\kw_tools\\hhh\\SEO\\contentgap.txt','r','utf-8')
  36. lines=fr.readlines()
  37. lst=[]
  38. for l in lines:
  39. lst.append(l.replace('\n',''))
  40. headers = {
  41. "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
  42. "Content-Type": "application/x-www-form-urlencoded"
  43. }
  44. def restart_browser():
  45. options = webdriver.ChromeOptions()
  46. options.add_argument('user-data-dir=c:/tmp/profile')
  47. options.add_argument('--profile-directory=Default')
  48. driver=webdriver.Chrome(options=options)
  49. driver.set_window_size(1400,1000)
  50. return driver
  51. driver=restart_browser()
  52. driver.get('https://liff.googo.org/liff2/')
  53. time.sleep(10)
  54. elmt=driver.find_element(By.XPATH,"//button[@id='senddm']")
  55. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  56. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  57. time.sleep(12)
  58. #time.sleep(99999)
  59. for window_handle in driver.window_handles:
  60. # driver.switch_to(window_handle)
  61. driver.switch_to.window(window_handle)
  62. print(driver.title)
  63. if ('選擇傳送對象' in driver.title ) or ('Share with' in driver.title):
  64. driver.maximize_window()
  65. print('ok')
  66. # class="c-checkbox"
  67. # elmts=driver.find_elements(By.XPATH,"//input[@type='checkbox']")
  68. elmts=driver.find_elements(By.XPATH,"//div[@class='c-checkbox']")
  69. for elmt in elmts:
  70. print(elmt.text)
  71. # if elmt.text != 'LINE':
  72. # if 'ChoozMo' in elmt.text :
  73. if 'Jared' in elmt.text :
  74. if len(elmt.text)>2:
  75. # inp=elmt.find_element(By.TAG_NAME,"input")
  76. inp=elmt.find_element(By.XPATH,".//input")
  77. # elem = driver.switch_to.active_element
  78. print(inp)
  79. # inp.click()
  80. webdriver.ActionChains(driver).move_to_element(inp).perform()
  81. # d3 = driver.switch_to.active_element
  82. webdriver.ActionChains(driver).move_to_element(inp).click().perform()
  83. elmt2=driver.find_element(By.XPATH,"//button[@name='allow']")
  84. webdriver.ActionChains(driver).move_to_element(elmt2).perform()
  85. webdriver.ActionChains(driver).move_to_element(elmt2).click().perform()
  86. #elmt.input.click()
  87. # if window_handle != original_window:
  88. # driver.switch_to.window(window_handle)
  89. # break
  90. time.sleep(9999)