zoukankan      html  css  js  c++  java
  • 爬虫(2)

    # -*- coding:utf-8 -*-
    # 百度音乐热歌榜 Top500
    # Auth:Crane
    # Time:2014-6-17
    # V1.0
    # 缺点:只能抓取前50首,也就是第一页的,其他页的抓不到,呃,发现其实不用先写到文件再从文件中读出来,因为效果是一样的,如果去掉
    # .decode("utf-8"),那么能显示495个,但是是乱码
    
    import urllib2
    import re
    
    url='http://music.baidu.com/top/dayhot'
    content=urllib2.urlopen(url).read().decode("utf-8")
    
    reg=r'<a href="/song/.*?" title="(.*?)">.*?<span class="author_list" title="(.*?)">'
    music_re=re.compile(reg)
    music_list=re.findall(music_re,content)
    
    i=1
    for item in music_list:
     	print i,item[0]+'    '+item[1]
     	i+=1
    
    只能抓取前50首,也就是第一页的,其他页的抓不到,呃,发现其实不用先写到文件再从文件中读出来,因为效果是一样的,如果去掉
     .decode("utf-8"),那么能显示495个,但是是乱码,不知道是什么原因

     

  • 相关阅读:
    哈希表--扩展数组
    哈希表效率
    P=(1+1/(1-L))/2
    函数推进
    简单函数2
    简单函数
    getting data from the keybroad
    nutch-2.2.1 hadoop-1.2.1 hbase-0.92.1 集群部署(实用)
    hbase zookeeper独立搭建
    Orchard 介绍
  • 原文地址:https://www.cnblogs.com/crane-practice/p/3793722.html
Copyright © 2011-2022 走看看