Re: [問題] urllib2抓取需驗證的網站
※ 引述《Jason1122 (Jason1122)》之銘言:
引言吃光~~
試試看這樣的方式:
import urllib, urllib2, cookielib
data = {'log' : 'xxxxx',
'pwd' : 'yyyyy',
'redirect_to': '/test/ROMI/?page_id=11',
'testcookie': '1',
'wp-submit':'Log In'}
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode(data)
opener.open('http://www.agileinsights.com/test/ROMI/wp-login.php', login_data)
resp = opener.open('http://www.agileinsights.com/test/ROMI/?page_id=11')
print resp.read()
網頁在登入完成後,沒有給任何內容(Content-Length:0)
只有在header給location和cookie,
就帶著這cookie,去你要的頁面抓吧。
這樣應該就會抓到你要的資料了 :)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.74.124.193
推
10/13 18:00, , 1F
10/13 18:00, 1F
→
10/13 18:01, , 2F
10/13 18:01, 2F
→
10/13 18:40, , 3F
10/13 18:40, 3F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):