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
  • 相关阅读:
    面向对象(Object Oriented)
    文件操作
    函数
    dict--字典
    list--列表
    Ubuntu_18.04安装网易云音乐
    初识数据类型
    css控制内容显示,自动加"..."
    css固定元素位置(fixed)
    解决IE下iframe默认有白色背景的bug
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349011.html
Copyright © 2011-2022 走看看