Browser_ads_kw.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from typing import NoReturn
  2. from selenium import webdriver
  3. import time
  4. import networkx as nx
  5. import dataset
  6. import pickle
  7. import codecs
  8. from selenium.webdriver.common import keys
  9. from selenium.webdriver.common.keys import Keys
  10. import sys
  11. import os
  12. import time
  13. import re
  14. import pandas as pd
  15. import df2sheet
  16. from browser_common import JBrowser
  17. import datetime
  18. import dataset
  19. #db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
  20. def get_designer_statistics():
  21. global db
  22. jb=JBrowser()
  23. data=""
  24. jb.set_profile_path("Profile 7")
  25. # googleurl='https://ads.google.com/aw/keywordplanner/'
  26. # googleurl='https://ads.google.com/aw/overview?ocid=600024232&euid=459838964&__u=6055300436&uscid=600024232&__c=2195332968&authuser=0&subid=ALL-zh-TW-et-g-aw-c-home-awhp_xin1_signin!o2'
  27. googleurl='https://ads.google.com/aw/keywordplanner/home?ocid=600024232&euid=459838964&__u=6055300436&uscid=600024232&__c=2195332968&authuser=0&subid=ALL-zh-TW-et-g-aw-c-home-awhp_xin1_signin%21o2'
  28. jb.get(googleurl)
  29. driver=jb.get_driver()
  30. time.sleep(40)
  31. print('after sleep')
  32. # elmts=driver.find_elements_by_xpath("//div[@class='keyword-text _ngcontent-owh-97']")
  33. elmts=driver.find_elements_by_xpath("//zippy-icon/..//keyword-text")
  34. for elmt in elmts:
  35. print(elmt.text)
  36. data+=elmt.text+"\n"
  37. fw=codecs.open('c:/tmp/out.txt','w','utf-8')
  38. fw.write(data)
  39. fw.close()
  40. # print(elmt)
  41. time.sleep(9999)
  42. return 'ok'
  43. get_designer_statistics()