Python抓取Discuz!用户名脚本代码
2013-12-30 17:18
477 查看
最近学习Python,于是就用Python写了一个抓取Discuz!用户名的脚本,代码很少但是很搓。思路很简单,就是正则匹配title然后提取用户名写入文本文档。程序以百度站长社区为例(一共有40多万用户),挂在VPS上就没管了,虽然用了延时但是后来发现一共只抓取了50000多个用户名就被封了。。。
代码如下:
# -*- coding: utf-8 -*-
# Author: 天一
# Blog: http://www.90blog.org
# Version: 1.0
# 功能: Python抓取百度站长平台用户名脚本
import urllib
import urllib2
import re
import time
def BiduSpider():
pattern = re.compile(r'<title>(.*)的个人资料 百度站长社区 </title>')
uid=1
thedatas = []
while uid <400000:
theUrl = "http://bbs.zhanzhang.baidu.com/home.php?mod=space&uid="+str(uid)
uid +=1
theResponse = urllib2.urlopen(theUrl)
thePage = theResponse.read()
#正则匹配用户名
theFindall = re.findall(pattern,thePage)
#等待0.5秒,以防频繁访问被禁止
time.sleep(0.5)
if theFindall :
#中文编码防止乱码输出
thedatas = theFindall[0].decode('utf-8').encode('gbk')
#写入txt文本文档
f = open('theUid.txt','a')
f.writelines(thedatas+'\n')
f.close()
if __name__ == '__main__':
BiduSpider()
最终成果如下:
您可能感兴趣的文章:
相关文章推荐
- Python抓取Discuz!用户名脚本代码
- 利用python脚本抓取AC的代码[爬虫+HTMLParser+handle_entityref+正则表达式+模拟登陆+文件操作]
- python抓取网页图片的脚本
- Python代码中的捕捉性能-CPU分析(Python脚本)
- 零基础写python爬虫之抓取百度贴吧代码分享
- [python]抓取2011年县及县以上行政区划代码
- python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例
- 代码干货 | MySQL上云同步脚本-Python3
- python 脚本(获取指定文件夹、指定文件格式、的代码行数、注释行数)
- Python之多线程爬虫抓取网页图片的示例代码
- 利用Python网络爬虫抓取豆瓣首页图片代码分享
- 用批处理/注销脚本清除 存储用户名和密码 列表的代码
- python刷投票的脚本实现代码
- python将人民币转换大写的脚本代码
- python将人民币转换大写的脚本代码
- 抓取bing图片的Python代码
- python脚本处理代码注释规范化
- Phantomjs抓取渲染JS后的网页(Python代码)
- Python实现自动添加脚本头信息的示例代码
- 手把手教你用Python抓取热门景点热力图!(附代码)