Пример #1
0
def search(keyword, search_url):
    try:
        browser.get(search_url)
        input = wait.until(
            EC.presence_of_element_located((By.CSS_SELECTOR, '#q')))
        submit = wait.until(
            EC.element_to_be_clickable(
                (By.CSS_SELECTOR,
                 'body > div.g-top > div > div > form > input.u-magnifier')))
        input.send_keys(keyword)
        submit.click()
        time.sleep(1)

        submit2 = wait.until(
            EC.element_to_be_clickable((
                By.CSS_SELECTOR,
                'body > div.search-column1 > div.left-suffix > div > ul.label-block.js-result > li:nth-child(2)'
            )))
        submit2.click()
        print(
            EC.findElement(
                By.cssSelector(
                    "body > div.search-column1 > div.right-content > ul > li:nth-child(1) > a > p"
                )))
        news_num = wait.until(
            EC.presence_of_element_located((
                By.xpath,
                'body > div.search-column1 > div.right-content > div > p[2]')))
        return news_num.text
    except TimeoutException:
        print('搜索超时')
        return search(keyword, search_url)
Пример #2
0
 def experiment(self, a):
     self.wd.find_element(By.cssSelector('span[class=\"title\"]:contains(' + someText + ')'))
     self.wd.find_element_by_xpath()
     self.wd.find_element_by_class_name('forgot')
     self.wd.find_element_by_link_text('Forgot password')
     self.wd.find_element_by_css_selector()
Пример #3
0
 def class_name(self, element_class_name):
     find_by_class_name = self.driver.findElement(
         By.cssSelector(element_class_name))
     return find_by_class_name
Пример #4
0
driver.get(url)


# element = WebDriverWait(driver,30).until(EwC.find_elements_by_partial_link_text('https://astrogeology.usgs.gov/search/map/Mars/Viking/cerberus_enhanced'))


#%%
url


#%%
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

wait = WebDriverWait(driver, 10)
driver.findElement(By.cssSelector("input:contains(^description$)")).click();
# element = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="product-section"]/div[2]/div[1]/a')))
# element.click()

# Driver.findElement(By.xpath("//li[contains(.,'Add Dexter')]//input[@type='checkbox']")).click();


#%%
all_names = soup.find_all('a', class_='href')
for x in all_names:
    print(x.get('search'))


#%%

Пример #5
0
chrome_options = Options()
#chrome_options.add_argument('--headless')
mobile_emulation = {"deviceName": "iPhone X"}
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/Users/jaysonkadlecek/desktop/chromedriver 2',
                     chrome_options=chrome_options)
d.get("https://www.instagram.com/accounts/login/")
assert "Login" in d.title

wait = WebDriverWait(d, 100)

username = d.find_element_by_name('username').send_keys(
    credentials['username'])
password = d.find_element_by_name('password').send_keys(
    credentials['password'])
login_button = d.find_element_by_xpath("//button[@type='submit']")

login_button.click()

try:
    element = WebDriverWait(d, 10).until(
        EC.presence_of_element_located(
            (By.cssSelector(".mt3GC > button:nth-child(1)"))))
finally:
    d.find_element_by_css_selector(".mt3GC > button:nth-child(1)").click()
    d.find_element_by_css_selector(".xWeGp").click()

print str(element.text)
Пример #6
0
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.maximize_window()
driver.get("https://fyonecardpre.cdwit120.com?redirect=mine")
driver.find_element_by_class_name('link').click()
driver.find_element_by_xpath('//*[@id="app"]/div/footer/a[1]/div[2]').click()
time.sleep(2)
driver.find_element_by_xpath('//*[@id="app"]/div/footer/a[2]/div[1]/div').click()
time.sleep(2)
driver.find_element_by_xpath('//*[@id="app"]/div/footer/a[3]/div[1]/div').click()
time.sleep(2)
driver.find_element_by_xpath('//*[@id="app"]/div/footer/a[4]/div[1]/div').click()
time.sleep(2)

driver.find_element(By.CLASS_NAME("input.fy-flex-2")).clear();
driver.findElement(By.cssSelector("input.fy-flex-2")).sendKeys("13333333338");
driver.findElement(By.xpath("//input[@type='password']")).clear();
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("111111");
driver.findElement(By.xpath("//div[@id='app']/div/div[2]/button")).click();
driver.findElement(By.cssSelector("div.header-content")).click();
driver.findElement(By.linkText("退出登录")).click();
driver.findElement(By.cssSelector("input.fy-flex-2")).clear();
driver.findElement(By.cssSelector("input.fy-flex-2")).sendKeys("13333333338");
driver.findElement(By.xpath("//input[@type='password']")).clear();
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("111111");
driver.findElement(By.xpath("//div[@id='app']/div/div[2]/button")).click();
driver.findElement(By.cssSelector("div.link")).click();
driver.findElement(By.cssSelector("div.mine-icon.icon-img")).click();
driver.findElement(By.cssSelector("img.img")).click();
driver.findElement(By.linkText("退出登录")).click();
driver.findElement(By.cssSelector("input.fy-flex-2")).clear();