Python爬虫实战:获取网站新闻标题并解析
#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('//h1[@class="news_title"]/text()')[0] print(newtitle) #end***
原文地址: https://www.cveoy.top/t/topic/owor 著作权归作者所有。请勿转载和采集!