python使用selenium和chrome自动操作浏览器

from selenium import webdriver
from time import sleep
from bs4 import BeautifulSoup
url = "http://www.baidu.com"

brower = webdriver.Chrome()
brower.get(url)
brower.find_element_by_id('kw').send_keys('name')
brower.find_element_by_id('su').click()
sleep(3)
#print(brower.page_source)
brower.find_element_by_link_text('name_百度百科').click()
sleep(3)
data = brower.page_source
soup = BeautifulSoup(data,'html.parser')
sleep(2)
d = soup.find('div','c-span18 c-span-last')
print(d.getText())

你可能感兴趣的:(python使用selenium和chrome自动操作浏览器)