python爬虫

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python爬虫相关的知识,希望对你有一定的参考价值。

这里使用的是xpath这个第三方python库

使用 from lxml import etree 导入

 

使用:

select = etree.html(html)

content = select.xpath()

for each in content:

  print each

 

 

一个简单的demo:

from lxml import etree


html = ‘‘‘
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input id=‘name1‘ href = ‘www.hao123.com‘></input>
    <input id=‘name2‘></input>
        xxxx


</body>
</html>
‘‘‘
select = etree.HTML(html)

content = select.xpath("//body/input[@id=‘name1‘]/@href")

for each in content:
    print each
print "end"

 

以上是关于python爬虫的主要内容,如果未能解决你的问题,请参考以下文章

Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段

python爬虫学习笔记-M3U8流视频数据爬虫

爬虫遇到头疼的验证码?Python实战讲解弹窗处理和验证码识别

python网络爬虫

Python 利用爬虫爬取网页内容 (div节点的疑惑)

为啥我的python爬虫界面与博主不一样