sel_local.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import sys
  2. import time
  3. sys.path.insert(0,'./web')
  4. import browser_common
  5. from selenium import webdriver
  6. from selenium.webdriver.common.keys import Keys
  7. from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
  8. jb=browser_common.JBrowser()
  9. #jb.set_profile_path('Profile 7')
  10. jb.set_profile_path(None)
  11. #jb.get('https://www.similarweb.com/website/yahoo.com/')
  12. #jb.get('https://www.similarweb.com/website/ptt.cc/')
  13. #jb.get('https://www.similarweb.com/website/591.com.tw/')
  14. #jb.get('https://data.similarweb.com/api/v1/data?domain=591.com.tw')
  15. driver=jb.get_driver()
  16. jb.get('https://google.com')
  17. #driver.add_script('const setProperty = () => { Object.defineProperty(navigator, "webdriver", { get: () => false, }); }; setProperty();')
  18. #jb.get('https://www.similarweb.com/')
  19. #jb.get('https://data.similarweb.com/api/v1/data?domain=cnn.com')
  20. #jb.get('https://www.similarweb.com/')
  21. time.sleep(2)
  22. driver.execute_script("window.location.href = 'https://www.similarweb.com';")
  23. #jb.get('https://www.similarweb.com/')
  24. elmt=driver.find_element_by_xpath("//input[@class='app-search__input']")
  25. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  26. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  27. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  28. time.sleep(5)
  29. elmt.send_keys('similarweb.com')
  30. elmt=driver.find_element_by_xpath("//button[@class='swui-button swui-button--solid swui-button--primary swui-button--brand swui-button--sm']")
  31. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  32. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  33. time.sleep(10)
  34. #src=driver.page_source
  35. #print(src)
  36. #time.sleep(9999)
  37. #class="websiteRanks-valueContainer js-websiteRanksValue"
  38. elmt=driver.find_element_by_xpath("//a[@data-analytics-label='Country Rank/158']")
  39. print(elmt.text)
  40. elmt=driver.find_element_by_xpath("//a[@data-analytics-label='Category Rank/computers-electronics-and-technology/social-networks-and-online-communities']")
  41. print(elmt.text)
  42. elmts=driver.find_elements_by_xpath("//div[@class='websiteRanks-valueContainer js-websiteRanksValue']")
  43. for elmt in elmts:
  44. print(elmt.text)