Python crawls Discuz! User name script code

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.