首页 > 编程语言 > 详细

python3 获取html内容中的a链接与内容

时间:2020-06-23 11:51:06      阅读:116      评论:0      收藏:0      [点我收藏+]
# -*- coding:utf8 -*-
import requests
import lxml.html

# 获取html内容中的a链接与内容
chapters_url = "http://www.civil.tsinghua.edu.cn/ce/83.html"
html = requests.get(chapters_url).content
selector = lxml.html.fromstring(html)
res = selector.xpath("///a/text()")
res1 = selector.xpath("///a/@href")
# print(res)
# print(res1)

for i,s in enumerate(res):
    print(res1[i])
    print(s)

  

python3 获取html内容中的a链接与内容

原文:https://www.cnblogs.com/todarcy/p/13180986.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!