Python抓取Discuz!用户名脚本代码
时间:2023-06-20 00:34:40
最近学习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()
最终成果如下:
标签:Discuz,用户名脚本,Python
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 实现返回一个列表中出现次数最多的元素方法
2023-01-04 14:36:54
JS表格排序新法
2010-07-09 06:40:13
python缺失值的解决方法总结
2023-07-28 23:47:38
golang 输出重定向:fmt Log,子进程Log,第三方库logrus的详解
2024-04-27 15:40:14
在生成的静态页面中统计点击次数
2009-11-19 13:20:00
如何利用python实现Simhash算法
2021-06-13 20:12:49
![](https://img.aspxhome.com/file/2023/1/109861_0s.png)
详解基于python的全局与局部序列比对的实现(DNA)
2021-03-29 13:23:31
![](https://img.aspxhome.com/file/2023/9/68479_0s.png)
如何愉快地迁移到 Python 3
2021-06-25 19:44:17
详解Python3序列赋值、序列解包
2022-04-19 05:24:51
python多线程抓取天涯帖子内容示例
2021-03-18 11:56:42
php实现的简单检验登陆类
2023-11-22 06:13:33
python编写俄罗斯方块
2023-04-02 11:03:06
在ASP.NET 2.0中操作数据之二十二:为删除数据添加客户端确认
2024-05-09 09:03:54
![](https://img.aspxhome.com/file/2023/0/129810_0s.png)
为您解读CSS优先级
2009-06-18 18:29:00
![](https://img.aspxhome.com/file/UploadPic/20096/18/01-66s.gif)
es6函数之严格模式用法实例分析
2023-08-09 06:15:40
python GUI库图形界面开发之PyQt5切换按钮控件QPushButton详细使用方法与实例
2021-06-13 09:13:14
![](https://img.aspxhome.com/file/2023/0/76840_0s.png)
一篇文章教你用Python实现一键文件重命名
2022-09-21 20:18:38
![](https://img.aspxhome.com/file/2023/8/71508_0s.jpg)
Python自然语言处理 NLTK 库用法入门教程【经典】
2022-10-06 04:36:54
使用python opencv对目录下图片进行去重的方法
2023-07-06 20:04:13
Python实现Kerberos用户的增删改查操作
2023-07-29 09:39:52
![](https://img.aspxhome.com/file/2023/3/61483_0s.jpg)