2018年3月18日星期日

[Python]网络爬虫(六):一个简单的百度贴吧的小爬虫

[python] view plain copy
  1. # -*- coding: utf-8 -*-  
  2. #---------------------------------------  
  3. #   程序:百度贴吧爬虫  
  4. #   版本:0.1  
  5. #   作者:why  
  6. #   日期:2013-05-14  
  7. #   语言:Python 2.7  
  8. #   操作:输入带分页的地址,去掉最后面的数字,设置一下起始页数和终点页数。  
  9. #   功能:下载对应页码内的所有页面并存储为html文件。  
  10. #---------------------------------------  
  11.    
  12. import string, urllib2  
  13.    
  14. #定义百度函数  
  15. def baidu_tieba(url,begin_page,end_page):     
  16.     for i in range(begin_page, end_page+1):  
  17.         sName = string.zfill(i,5) + '.html'#自动填充成六位的文件名  
  18.         print '正在下载第' + str(i) + '个网页,并将其存储为' + sName + '......'  
  19.         f = open(sName,'w+')  
  20.         m = urllib2.urlopen(url + str(i)).read()  
  21.         f.write(m)  
  22.         f.close()  
  23.    
  24.    
  25. #-------- 在这里输入参数 ------------------  
  26.   
  27. # 这个是山东大学的百度贴吧中某一个帖子的地址  
  28. #bdurl = 'http://tieba.baidu.com/p/2296017831?pn='  
  29. #iPostBegin = 1  
  30. #iPostEnd = 10  
  31.   
  32. bdurl = str(raw_input(u'请输入贴吧的地址,去掉pn=后面的数字:\n'))  
  33. begin_page = int(raw_input(u'请输入开始的页数:\n'))  
  34. end_page = int(raw_input(u'请输入终点的页数:\n'))  
  35. #-------- 在这里输入参数 ------------------  
  36.    
  37.   
  38. #调用  
  39. baidu_tieba(bdurl,begin_page,end_page)  



2 条评论:

  1. Do you need to increase your credit score?
    Do you intend to upgrade your school grade?
    Do you want to hack your cheating spouse Email, whatsapp, Facebook, instagram or any social network?
    Do you need any information concerning any database.
    Do you need to retrieve deleted files?
    Do you need to clear your criminal records or DMV?
    Do you want to remove any site or link from any blog?
    you should contact this hacker, he is reliable and good at the hack jobs..
    contact : cybergoldenhacker at gmail dot com

    回复删除
  2. I can’t say much but with my experience through divorce, I had no one until I met hackingsetting50@gmail.com online then I contacted him, surprisingly he helped me hack into my partner's phone and all his social media platforms and i can now access everything and even documented and printed stuffs to show as evidence , now I’m happy with my kids and working for Riches. I hope this helps anyone in need.

    Thanks.

    回复删除

注意:只有此博客的成员才能发布评论。

Also Read: