python 使用lxml解析html(xpath)
2016-07-11 11:25
856 查看
举个栗子好了:#coding:utf-8
import urllib2
from lxml import etree
f = urllib2.urlopen("http://www.ydylcn.com/skwx_ydyl/sublibrary?ID=8724&SiteID=1&showDetail=true&RootFlag=Y")
conent = f.read()
article_name = etree.HTML(conent)
print article_name.xpath("//div[@class='zt_list'][1]/h2/a/text()")[0]
重点就是,使用lxml.etree.HTML
import urllib2
from lxml import etree
f = urllib2.urlopen("http://www.ydylcn.com/skwx_ydyl/sublibrary?ID=8724&SiteID=1&showDetail=true&RootFlag=Y")
conent = f.read()
article_name = etree.HTML(conent)
print article_name.xpath("//div[@class='zt_list'][1]/h2/a/text()")[0]
重点就是,使用lxml.etree.HTML
相关文章推荐
- python中json对象转换出错解决方法
- saltstack学习汇总
- python2.0_s12_day12_css样式详解
- 使用python测试你的电脑开启最大线程数
- Python爬虫实战(3):安居客房产经纪人信息采集
- Python获取当前时间的前(后)N天,前(后)N周,前(后)N月
- Python新手学习基础之数据类型——变量
- 深入Python(2): __init__.py 用法
- TensorFlow实战— —K-Means聚类
- Celery 踩坑笔记
- DAY7:leetcode #14 Longest Common Prefix
- Python中关于字符串问题
- 关于python urlopen 一个类似radio流的timeout方法
- python平行(3):【parallel python】与【sklearn joblib的parallel和delayed】性能对比
- [Jenkins] Use python requests to programatically get and set Jenkins job configuration
- python安装第三方插件出现的错误
- 爬虫笔记
- 一个程序学会python的流程控制
- mac 安装robotFramwork环境 以及wxPython 无法安装问题解决 (非常有用)
- Python collections模块实例讲解