欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)自動(dòng)登錄百度空間的方法

 更新時(shí)間:2017年06月10日 11:21:57   作者:JoeBlackzqq  
這篇文章主要介紹了Python實(shí)現(xiàn)自動(dòng)登錄百度空間的方法,涉及Python的http請(qǐng)求發(fā)送、獲取響應(yīng)、cookie操作等相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了Python實(shí)現(xiàn)自動(dòng)登錄百度空間的方法。分享給大家供大家參考,具體如下:

開發(fā)環(huán)境:Fedora12 + Python2.6.2

#!/usr/bin/python
# coding: GBK
import urllib,urllib2,httplib,cookielib
def auto_login_hi(url,name,pwd):
  url_hi="http://passport.baidu.com/?login"
  #設(shè)置cookie
  cookie=cookielib.CookieJar()
  cj=urllib2.HTTPCookieProcessor(cookie)
  #設(shè)置登錄參數(shù)
  postdata=urllib.urlencode({'username':name,'password':pwd})
  #生成請(qǐng)求
  request=urllib2.Request(url_hi,postdata)
  #登錄百度
  #opener=urllib2.build_opener(request,cj)
  opener=urllib2.build_opener(cj)
  f=opener.open(request)
  #打開百度HI空間頁面
  hi_html=opener.open(url)
  return hi_html
if __name__=='__main__':
  name='zhouciming'
  password='xxx'
  url='http://hi.baidu.com/zhouciming'
  h=auto_login_hi(url,name,password)
  print h.read()

運(yùn)行結(jié)果:

[zcm@python #33]$./bai.py
<!DOCTYPE html>
<HTML XMLNS="http://www.w3.org/1999/xhtml" LANG="zh-CN">
<HEAD><!--STATUS OK-->
  <META http-equiv="Content-Type" CONTENT="text/html;charset=GBK" />
  <TITLE>個(gè)人主頁</TITLE>
</HEAD>
<BODY>
<script language="javascript">
location.href="/zhouciming/home" rel="external nofollow" ;
</script>
</BODY>
</HTML>

通過運(yùn)行結(jié)果可以看到,登錄成功了。網(wǎng)頁自動(dòng)跳轉(zhuǎn)到 /zhouciming/home

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python URL操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論