|
#!/usr/bin/python |
|
# -*- coding: utf-8 -*- |
|
|
|
''' |
|
you can find a test web login interface like: https://gist.github.com/mschoebel/9398202 |
|
download and install EditThisCookie |
|
https://chrome.google.com/webstore/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg |
|
click the icon and copy the cookie string |
|
''' |
|
|
|
try: |
|
import cookielib |
|
except: |
|
import http.cookiejar as cookielib |
|
|
|
# different cookies format |
|
MozillaCookie = ''' |
|
// Semicolon separated Cookie File |
|
// This file was generated by EditThisCookie |
|
// Details: http://www.cookiecentral.com/faq/#3.5 |
|
// Example: http://www.tutorialspoint.com/javascript/javascript_cookies.htm |
|
Set-Cookie3: session=MTU4Njc2NzM0OXxGZVhSdTlhbWRZRVZjVENiUnZ1MWJYUXFCeEtJWGJPaFVPYUMxR3YtUUE0N2RJVFUyS2ZsWGFIMnJETzhGeWx6cEE9PXyW2nKjfVu1Jg4MyPQsNjNBgsoyBvA_K17iL-HYagzIaQ==; path="/"; domain=127.0.0.1; path_spec; expires="0"; version=0 |
|
''' |
|
|
|
# you need add '#LWP-Cookies-2.0' first line |
|
LWPCookieJar = ''' |
|
#LWP-Cookies-2.0 |
|
// Semicolon separated Cookie File |
|
// This file was generated by EditThisCookie |
|
// Details: http://www.cookiecentral.com/faq/#3.5 |
|
// Example: http://www.tutorialspoint.com/javascript/javascript_cookies.htm |
|
Set-Cookie3: session=MTU4Njc2NzM0OXxGZVhSdTlhbWRZRVZjVENiUnZ1MWJYUXFCeEtJWGJPaFVPYUMxR3YtUUE0N2RJVFUyS2ZsWGFIMnJETzhGeWx6cEE9PXyW2nKjfVu1Jg4MyPQsNjNBgsoyBvA_K17iL-HYagzIaQ==; path="/"; domain=127.0.0.1; path_spec; expires="0"; version=0 |
|
''' |
|
|
|
with open('cookies.txt', 'r') as f: |
|
f.read() |
|
|
|
cj = cookielib.MozillaCookieJar('cookies.txt') |
|
cj = cookielib.LWPCookieJar('cookies.txt') |
|
|
|
# ignore_discard=True is important |
|
cj.load('cookies.txt', ignore_discard=True) |
|
|
|
import urllib2 |
|
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) |
|
print opener.open('https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm').read() |
|
|
|
import requests |
|
session = requests.Session() |
|
session.cookies = cookielib.LWPCookieJar('cookies.txt') |
|
session.cookies.load(ignore_discard=True) |
|
print session.get('https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm').text |