Use selenium to crawl news

from selenium import webdriver
import  time
# 创建 Webwd 实例对象,指明使用chrome浏览器驱动
wd = webdriver.Chrome(r'D:\tools-work\chromedriver_win32\chromedriver.exe')

wd.implicitly_wait(5)#等待时间 一定要写
# 链接地址
# wd.get('https://www.mps.gov.cn/n2253534/n2253535/index.html')
wd.get('https://www.mps.gov.cn/n2253534/n2253535/index.html')
titles = wd.find_elements_by_xpath('//*[@id="comp_7627565"]/ul/li/a')
for x in titles:
    print(x.text)

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_41665637/article/details/112303711