+ -
当前位置:首页 → 问答吧 → 這個網站該如何自動登陸

這個網站該如何自動登陸

时间:2010-11-14

来源:互联网

想自動登陸pchome網站,代碼已經寫了大部分,可是有個問題,下面將詳細說明
(1)pchome的部分登錄畫面如下

其中藍色的登入方塊每次登陸時都會出現在不同的位置,而只有滑鼠點擊在登入方塊上才能正確登陸
(2)我用httpfox取得登錄時post的資料,其畫面如下

其中藍色標註部分的x和y應是每次登陸時(1)中所述的登入方塊時出現的位置

已寫好的代碼如下

import urllib,http.cookiejar,re

username = ''  
passwd = '' 

def login():
  print('try to login...')

  cookie=http.cookiejar.CookieJar()
  opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie), urllib.request.HTTPHandler)
  urllib.request.install_opener(opener)

  print('...getting login form...')
  loginform = urllib.request.urlopen('https://member.pchome.com.tw/login.html?ref=http://www.pchome.com.tw/').read

()
  fnn = re.compile(r'name="fnn" value="(.*)"').findall(loginform)[0]
  mredirect = re.compile(r'name="mredirect" value="(.*)"').findall(loginform)[0]
  enc = re.compile(r'name="enc" value="(.*)"').findall(loginform)[0]

  postdata=urllib.urlencode({'ref':'http://stock.pchome.com.tw/
  'fun':fun,
  'mredirect':mredirect
'userID':username,
  'passwd':passwd,
  'x':,#這個不知道要如何取得
  'y':,#這個不知道要如何取得
  'enc':enc,
  })
  req = urllib2.Request(
  url = 'https://member.pchome.com.tw/login.html?ref=http://stock.pchome.com.tw/',
  data = postdata
  )

  req.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.9.0.19) Gecko/2010031422 

Firefox/3.0.19')
  req.add_header('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
  req.add_header('Accept-Encoding','gzip,deflate')

  print('...login form submitted')
  result = urllib.request.urlopen(req).read()
  print('...login succeed!')

現在的問題是不知道如何取得x和y的值(每次要登陸時都不一樣)

作者: iso230   发布时间: 2010-11-14

圖片沒上傳,再傳一次


作者: iso230   发布时间: 2010-11-14