xpath下的 href和text()

/li/a/@herf 这样取的应该是href的内容
/li/a/text() 这样取得是text内容
抄自https://blog.csdn.net/weixin_39263590/article/details/80046981
属性定位的写法:

("//标签名[ @属性= "属性值"]")

抄自https://www.cnblogs.com/yi-xixi/p/10972980.html

 

 

tree = etree.HTML(page_text)
biaoqian = tree.xpath('/html/body/div[2]/div/div[2]/div/div[2]/ul/li')
for i in biaoqian:
    print(i.xpath('.//i/@class'))
# 结果
'''
['l ewb-identification-ico ewb-identification01']
['l ewb-identification-ico ewb-identification02']
['l ewb-identification-ico ewb-identification03']
['l ewb-identification-ico ewb-identification07']
['l ewb-identification-ico ewb-identification09']
'''

有种, 爬的东西都是爬的文字的感觉。都可以通过文字爬的感觉。

posted @ 2020-04-23 00:44  learnacode  阅读(942)  评论(0编辑  收藏  举报