import sys import time sys.path.insert(0,'./web') import browser_common from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.firefox.firefox_binary import FirefoxBinary jb=browser_common.JBrowser() #jb.set_profile_path('Profile 7') jb.set_profile_path(None) #jb.get('https://www.similarweb.com/website/yahoo.com/') #jb.get('https://www.similarweb.com/website/ptt.cc/') #jb.get('https://www.similarweb.com/website/591.com.tw/') #jb.get('https://data.similarweb.com/api/v1/data?domain=591.com.tw') driver=jb.get_driver() jb.get('https://google.com') #driver.add_script('const setProperty = () => { Object.defineProperty(navigator, "webdriver", { get: () => false, }); }; setProperty();') #jb.get('https://www.similarweb.com/') #jb.get('https://data.similarweb.com/api/v1/data?domain=cnn.com') #jb.get('https://www.similarweb.com/') time.sleep(2) driver.execute_script("window.location.href = 'https://www.similarweb.com';") #jb.get('https://www.similarweb.com/') elmt=driver.find_element_by_xpath("//input[@class='app-search__input']") webdriver.ActionChains(driver).move_to_element(elmt).perform() webdriver.ActionChains(driver).move_to_element(elmt).click().perform() webdriver.ActionChains(driver).move_to_element(elmt).click().perform() time.sleep(5) elmt.send_keys('similarweb.com') elmt=driver.find_element_by_xpath("//button[@class='swui-button swui-button--solid swui-button--primary swui-button--brand swui-button--sm']") webdriver.ActionChains(driver).move_to_element(elmt).perform() webdriver.ActionChains(driver).move_to_element(elmt).click().perform() time.sleep(10) #src=driver.page_source #print(src) #time.sleep(9999) #class="websiteRanks-valueContainer js-websiteRanksValue" elmt=driver.find_element_by_xpath("//a[@data-analytics-label='Country Rank/158']") print(elmt.text) elmt=driver.find_element_by_xpath("//a[@data-analytics-label='Category Rank/computers-electronics-and-technology/social-networks-and-online-communities']") print(elmt.text) elmts=driver.find_elements_by_xpath("//div[@class='websiteRanks-valueContainer js-websiteRanksValue']") for elmt in elmts: print(elmt.text)