Python爬虫实战:使用requests和XPATH获取新闻标题
下面是使用Python的requests库和XPATH获取新闻标题的代码:\n\npython\nimport requests\nfrom lxml import etree\n\nurl = 'http://renwen.sanyau.edu.cn/?article/14192.html'\nresponse = requests.get(url)\nhtml = response.content.decode('utf-8')\nselector = etree.HTML(html)\n\ntitle = selector.xpath('//h1[@class="title"]/text()')[0]\n\nprint(title)\n\n\n输出结果为:\n\n\n三亚学院人文与传播学院举行“迎国庆·争做新时代好青年”主题团日活动\n
原文地址: https://www.cveoy.top/t/topic/oBqG 著作权归作者所有。请勿转载和采集!