37,720
社区成员
发帖
与我相关
我的任务
分享
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
try:
browser=webdriver.Chrome()
wait=WebDriverWait(browser,10)
browser.get('https://search.jd.com/Search?keyword=ipad')
inpt=wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'#J_bottomPage input')))
submit=wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'#J_bottomPage > span.p-skip > a')))
inpt.clear()
inpt.send_keys('2')
inpt.send_keys(Keys.ENTER)
time.sleep(5)
submit.click()
time.sleep(10)
except TimeoutException:
print 'failed'
try:
browser = webdriver.Chrome()
wait = WebDriverWait(browser, 10)
browser.get('https://search.jd.com/Search?keyword=ipad')
submit = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="J_bottomPage"]/span[1]/a[3]')))
try:
print('scroll')
browser.execute_script('arguments[0].scrollIntoView();', submit)
print('scroll ok')
except Exception as e1:
print('sroll fail')
print(repr(e1))
pass
time.sleep(2)
inpt = browser.find_element_by_xpath('//*[@id="J_bottomPage"]/span[1]/a[3]')
inpt.click()
time.sleep(2)
except Exception as e:
print 'failed'
print(repr(e))
[/quote]
try:
browser = webdriver.Chrome()
wait = WebDriverWait(browser, 10)
browser.get('https://search.jd.com/Search?keyword=ipad')
submit = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="J_bottomPage"]/span[1]/a[3]')))
try:
print('scroll')
browser.execute_script('arguments[0].scrollIntoView();', submit)
print('scroll ok')
except Exception as e1:
print('sroll fail')
print(repr(e1))
pass
time.sleep(2)
inpt = browser.find_element_by_xpath('//*[@id="J_bottomPage"]/span[1]/a[3]')
inpt.click()
time.sleep(2)
except Exception as e:
print 'failed'
print(repr(e))