码迷,mamicode.com
首页 > 编程语言 > 详细

杂记 使用Python采集网页内容

时间:2015-07-17 22:28:57      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:

BeautifulSoup  一个分析、处理DOM树的类库。

 

采集所有img标签的title属性的内容

# -*- coding: utf-8 -*- 

from    urllib.request    import    urlopen
from    urllib.error    import    HTTPError
from    bs4    import    BeautifulSoup

url  = "http://qa.beloved999.com/category/view?id=2"
url  = "http://beloved.finley.com/category/view?id=24"
html = urlopen(url)
bs   = BeautifulSoup(html.read(),"html.parser")
res  = bs.findAll("img", "item-image")
print(len(res))
for a in res:
    print(a[title])
    

发送的HTTP_USER_AGENT是Python-urllib/3.4。包含HTTP的信息有

‘HTTP_ACCEPT_ENCODING‘ => ‘identity‘
‘HTTP_CONNECTION‘ => ‘close‘
‘HTTP_HOST‘ => ‘beloved.finley.com‘
‘HTTP_USER_AGENT‘ => ‘Python-urllib/3.4‘  。

杂记 使用Python采集网页内容

标签:

原文地址:http://www.cnblogs.com/mafeifan/p/4655782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!