lxml获取日期

lxml使用xPath获取日期,xPath比较像路径

import requests
from lxml import etree
link='https://blog.csdn.net/even160941/article/list/1?'
headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0'}
r=requests.get(link,headers=headers)
html=etree.HTML(r.text)     ##转换成lxml格式
date=html.xpath('//span[@class="date"]/text()')     ##使用xpath获取信息,//span选取span元素,【】表示选取class为date的span元素,/text表示提取其中的文字
for each in date:
	print(each)

Python爬虫(五)
Python爬虫(五)

相关文章:

  • 2021-11-18
  • 2021-10-05
  • 2021-07-05
  • 2021-08-26
  • 2022-01-10
  • 2022-01-03
  • 2022-01-06
  • 2022-12-23
猜你喜欢
  • 2021-08-09
  • 2021-06-17
  • 2022-02-14
  • 2021-12-29
  • 2022-02-07
  • 2021-05-08
  • 2022-12-23
相关资源
相似解决方案