您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python抓取Discuz!用户名脚本代码

2025/10/18 3:42:27发布24次查看
最近学习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'(.*)的个人资料  百度站长社区 ')
     uid=1
     thedatas = []
     while uid          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()
最终成果如下:
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product