This article mainly introduces how to capture Discuz in Python! User name script code. if you need it, you can refer to the recently learned Python code. so you wrote a piece of Discuz in Python! Script of the user name. The code is very small, but very confusing. The idea is simple, that is, regex matches the title and extracts the user name to write it to the text document. The program uses the Baidu webmaster community as an example (a total of more than 0.4 million users), so it's okay to stick it to the VPS, although the latency was used, it was later found that a total of more than 50000 user names were captured, and they were blocked...
The code is as follows:
The code is as follows:
#-*-Coding: UTF-8 -*-
# Author: Tianyi
# Blog: http://www.90blog.org
# Version: 1.0
# Function: Python captures the user name script of Baidu webmaster platform
Import urllib
Import urllib2
Import re
Import time
Def BiduSpider ():
Pattern = re. compile (r'(. *) Personal data: Baidu webmaster community')
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 ()
# Regular expression matching username
TheFindall = re. findall (pattern, thePage)
# Wait 0.5 seconds to prevent frequent access from being disabled
Time. sleep (0.5)
If theFindall:
# Chinese encoding to prevent garbled output
Thedatas = theFindall [0]. decode ('utf-8'). encode ('gbk ')
# Writing txt text documents
F = open('theUid.txt ', 'A ')
F. writelines (thedatas + '\ n ')
F. close ()
If _ name _ = '_ main __':
BiduSpider ()
The final results are as follows: