Python爬虫实战:使用requests和xpath获取网页新闻标题
#begin*** #导入相关的两个库 import requests from lxml import etree
url='http://renwen.sanyau.edu.cn/?article/14263.html' res=requests.get(url) print('状态码',res.status_code)#此处需要补全代码 print('编码', res.encoding)#此处需要补全代码 #使用xpath解析网页,输出新闻标题,需要补全代码 html = etree.HTML(res.text) newtitle = html.xpath('//div[@class="content"]/h2/text()')[0] print(newtitle)
#end***
原文地址: https://www.cveoy.top/t/topic/owod 著作权归作者所有。请勿转载和采集!