爬新闻内容

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/c7643299/content.html')
titles = wd.find_element_by_xpath('/html/body/div/div[3]/div[2]/div[1]/p')

conten = wd.find_elements_by_xpath('//*[@id="ztdx"]//p')


#标题
# print(titles.text)
for x in conten:
    print(x.text)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41665637/article/details/112304115