爬虫類学習、selenium 1

2292 ワード

chromedriverファイルの配置
from selenium import webdriver
from time import sleep

# 
bro = webdriver.Chrome(executable_path='./chromedriver')
# 
bro.get('https://www.jd.com/')
search_text = bro.find_element_by_xpath('//*[@id="key"]')
search_text.send_keys('iphoneX')

btn = bro.find_element_by_xpath('//*[@id="search"]/div/div[2]/button')
btn.click()

sleep(2)

# (js )
bro.execute_script('window.scrollTo(0,document.body.scrollHeight)')
sleep(2)
bro.quit()