Python抓取Discuz!用户名脚本代码
2013-12-30 00:00
627 查看
最近学习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抓取网页内容应用代码分析
- python写的小巧的(14行有效代码)随机密码生成小脚本工具
- python抓取动态网页---实例代码
- Linux下用Python脚本监控目录变化代码分享
- 写python脚本进行abaqus建模,抄某指导书中的一个简单的悬臂梁代码
- 使用Python3编写抓取网页和只抓网页图片的脚本
- python 脚本(获取指定文件夹、指定文件格式、的代码行数、注释行数)
- Python urllib、urllib2、httplib抓取网页代码实例
- C,C++代码中调用python脚本
- python 抓取网页代码
- Python抓取淘女郎网页信息以及代码下载
- 利用python脚本(xpath)抓取数据
- python备份文件以及mysql数据库的脚本代码
- 零基础写python爬虫之抓取糗事百科代码分享
- python网页抓取练手代码
- C调用Python脚本代码