- 论坛徽章:
- 0
|
py 3.x,运行后,查看源码可以发现登录的用户名。说明登录成功。- import urllib.request
- import urllib.parse
- import http.cookiejar
- import re
- posturl='http://bbs.chinaunix.net/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=Lybyc'
- url='http://bbs.chinaunix.net/member.php?mod=logging&action=login&logsubmit=yes'
- cookie = http.cookiejar.LWPCookieJar()
- cookie_support = urllib.request.HTTPCookieProcessor(cookie)
- opener = urllib.request.build_opener(cookie_support, urllib.request.HTTPHandler)
- urllib.request.install_opener(opener)
- h=urllib.request.urlopen(url)
- headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0','Referer':'http://bbs.chinaunix.net/member.php?mod=logging&action=login&logsubmit=yes','Host':'bbs.chinaunix.net'}
- postdata={'formhash':'97b00039',
- 'referer':'http://bbs.chinaunix.net/./',
- 'username':'zerostudy',
- 'password':'mingwenpasswd',
- 'cookietime':'2592000',
- 'loginsubmit':'true',
- 'return_type':''}
- postdata=urllib.parse.urlencode(postdata).encode('utf-8')
- request=urllib.request.Request(posturl,postdata,headers)
- response=urllib.request.urlopen(request)
- html=response.read().decode('gbk')
- s=urllib.request.urlopen('http://bbs.chinaunix.net/forum-24-1.html')
- print(s.read().decode('gbk'))
复制代码- <table width="100%" cellspacing="0" cellpadding="0" border="0" align="left">
- <td height="26px">
- <!--wangyingxin add 修改用户名 strart--><strong class="vwmy">你好,<a href="space-uid-181255.html" target="_blank" title="访问我的空间">zerostudy</a></strong>
- <!--wangyingxin add 修改用户名 end-->
- <span class="pipe">|</span>
复制代码 |
|