zoukankan      html  css  js  c++  java
  • 爬取li标签下的 的 href

    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    from lxml import etree
    
    # 获取文件元素
    from lxml import etree
    
    # 获取文件元素
    htmlEmt = etree.parse('test02.html')
    # 获取所有的 <li> 标签
    result = htmlEmt.xpath('//a/@href')
    print(result)
    print type(result)
    for x in result:
        # print x
        # print type(x)
        # print '-------------------------'
        print x
    
    	
    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/xpath/l1.py
    ['aaa', 'bbb']
    <type 'list'>
    aaa
    bbb
    
    Process finished with exit code 0
    
    爬取li标签下的<a> 的 href
    
    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    from lxml import etree
    
    # 获取文件元素
    from lxml import etree
    
    # 获取文件元素
    htmlEmt = etree.parse('test02.html')
    # 获取所有的 <li> 标签
    result = htmlEmt.xpath('//li/a/@href')
    print(result)
    print type(result)
    for x in result:
        # print x
        # print type(x)
        # print '-------------------------'
        print x
    
    	C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/xpath/l1.py
    ['aaa']
    <type 'list'>
    aaa
  • 相关阅读:
    A计划
    edu_6_4_1
    edu_6_2_2
    edu_6_3_1
    hdu 1205 吃糖果【鸽巢原理】
    float 为什么不能用== ,或者大于等于,或者小于等于
    素数筛法及其优化
    hdu 1106 排序
    hdu 1164 Eddy's research I
    java 格式化输出 printf 总结
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349011.html
Copyright © 2011-2022 走看看