下面是使用Python的requests库和XPATH获取新闻标题的代码:

import requests
from lxml import etree

url = 'http://renwen.sanyau.edu.cn/?article/14192.html'
response = requests.get(url)
html = response.content.decode('utf-8')
selector = etree.HTML(html)

title = selector.xpath('//h1[@class="title"]/text()')[0]

print(title)

输出结果为:

三亚学院人文与传播学院举行“迎国庆·争做新时代好青年”主题团日活动
使用requests库和XPATH获取新闻标题 httprenwensanyaueducnarticle14192html是三亚学院人文与传播学院新闻地址现在需要获取该链接的新闻标题。请完成程序。

原文地址: https://www.cveoy.top/t/topic/g8eS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录