Python爬虫实战:使用requests和XPATH获取新闻标题
以下是Python代码:
import requests
from lxml import etree
url = 'http://renwen.sanyau.edu.cn/?article/14192.html'
response = requests.get(url)
html = response.text
# 使用xpath解析html
selector = etree.HTML(html)
title = selector.xpath('//div[@class="article-box"]/h1/text()')[0]
print(title)
输出结果为:
三亚学院人文与传播学院举办'传媒与健康'主题论坛
原文地址: https://www.cveoy.top/t/topic/oBrt 著作权归作者所有。请勿转载和采集!