selenium(1)
from selenium import webdriver
from time import sleep
bro = webdriver.Chrome()
bro.get('https://www.taobao.com/')
#标签定位
search_input = bro.find_element_by_id('q').send_keys('苹果')
#点击搜索
#执行js代码让屏幕滚动
bro.execute_script('window.scrollTo(0,document.body.scrollHeight)')
sleep(1)
btn=bro.find_element_by_css_selector('.btn-search').click()
bro.get('https://baidu.com/')
sleep(1)
#h回退操作
bro.back()
#前进操作
bro.forward()
sleep(2)
bro.close
from selenium import webdriver
from lxml.etree import HTML
from time import sleep
# (实例化一个浏览器对象(传入浏览器的地址))
bro = webdriver.Chrome()
#想浏览器发送get请求
bro.get('http://scxk.nmpa.gov.cn:81/xk/')
#page_source 获取页面数据
page_cont=bro.page_source
#解析企业名称
etree=HTML(page_cont)
li_list=etree.xpath('//*[@id="gzlist"]/li')
print(li_list)
for i in li_list:
name=i.xpath('./dl/@title')[0]
sleep(2)
bro.quit()