18.Selenium+Python案例 -- 豆瓣
一.具体代码实现:
from selenium import webdriver driver = webdriver.Firefox() driver.get('https://www.douban.com/') driver.find_element_by_id('form_email').clear() driver.find_element_by_id('form_email').send_keys('XXX') driver.find_element_by_id('form_password').clear() driver.find_element_by_id('form_password').send_keys('XXX') driver.find_element_by_xpath('//*[@id="lzform"]/fieldset/div[3]/input').click() with open('C://1.html','wb') as file: #读取豆瓣源代码保存到C://1.html file.write(driver.page_source.encode('UTF-8')) driver.quit()