Getting started with Python mini exercise 003 Get account information with Cookielib demo login

Source: Internet
Author: User

For convenience, use Chinaunix's account to get the account subject. Some sites may require a verification code to find some sites that do not have a verification code

The following ****** a lot of asterisks are private information, so use asterisks instead

#!/usr/bin/python#-*-encoding:utf-8-*-ImportUrllibImportUrllib2ImportCookielibImportReImportChardet #判断字符串编码的包 with a detailed example of Charset.detect (str) http://www.cnblogs.com/zhanhg/p/4392089.htmlfilename /c0>='Cookie.txt'#declares a Mozillacookiejar object instance to hold the cookie, and then writes the fileCookie =Cookielib. Mozillacookiejar (filename)#handler = Urllib2. Httpcookieprocessor (Cookie)#opener = Urllib2.build_opener (handler)Opener =Urllib2.build_opener (urllib2. Httpcookieprocessor (cookie)) PostData=Urllib.urlencode ({'Stuid':' *******',    'pwd':'*******'    })#URL link for login ChinaunixLoginurl ='Http://bbs.chinaunix.net/member.php?mod=logging&action=login&logsubmit=yes'#impersonate a login and save the cookie to a variableresult =Opener.open (loginurl,postdata)#Save the cookie to the Cookie.txt fileCookie.save (Ignore_discard=true, ignore_expires=True)#links to queriesGradeurl ='http://bbs.chinaunix.net/home.php?m*********************'result=Opener.open (gradeurl) HTML=result.read () Reg= R'<a href\=\ "thread.*?" > (. *?) </a>'a=Re.findall (reg,html) forXinchA:Print(X.decode ('gb2312'))

Getting started with Python mini exercise 003 Get account information with Cookielib demo login

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.