Python urllib2 captures Wordpress user learning Notes

Source: Internet
Author: User

Just learn python, try to find an example to try.

The code is as follows Copy Code

#!/usr/bin/env python
#coding =utf-8
Import Sys
Import Urllib2
Import string
Import re
Import OS
Demo = "" "

"""
Try
If Len (SYS.ARGV) < 2:
Print "----------------------------------------"
Print Demo
Print "----------------------------------------"
Sys.exit ()
LJ = "/?author="
url = sys.argv[1] + LJ
Path = OS.GETCWD () #获取文件路径
Url_name = Re.findall (' http://(. *\w) ', sys.argv[1]) #获取域名
Url_name_txt = url_name[0] + '. txt '
Print "Username to%s\\%s"% (path,url_name_txt)
For I in Xrange (1,1111): #循环ID
web = URL + str (i)
Code = Urllib2.urlopen (Web). Read () #获取源码
Username = Re.findall (' <title> (. *\w) | ', code) #正则匹配用户名
username_txt = open (str (url_name_txt), ' a ')
Username_txt.writelines (username)
Username_txt.writelines ("\ n")
Username_txt.close ()
Except
print ' Just for wp.py '

Effect Chart:

Related Article

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.