Bir web sitesine giriş yapmak için Selenium'u kullanmaya çalışıyorum ve daha sonra RESTy isteklerini yapmak için urllib2'yi kullanıyorum. Yine de çalışması için, aynı Selenium seansını kullanabilmek için urllib2'ye ihtiyacım var.Bir oturum çerezini selenyumdan kullanarak urllib2
selenyum ile giriş günlüğü harika çalıştı ve ben
self.driver.get_cookies()
çağırabilir ve selenyum haberi tüm çerezleri listesi var ve böyle bir şeyler arayan biter:
[{u'domain': u'my.awesome.web.app.local',
u'expiry': 1319230106,
u'name': u'ci_session',
u'path': u'/',
u'secure': False,
u'value': u'9YEz6Qs9rNlONzXbZPZ5i9jm2Nn4HNrbaCJj2c%2B...'
}]
# self.driver is my selenium driver
all_cookies = self.driver.get_cookies()
cp = urllib2.HTTPCookieProcessor()
cj = cp.cookiejar
for s_cookie in all_cookies:
cj.set_cookie(
cookielib.Cookie(
version=0
, name=s_cookie['name']
, value=s_cookie['value']
, port='80'
, port_specified=False
, domain=s_cookie['domain']
, domain_specified=True
, domain_initial_dot=False
, path=s_cookie['path']
, path_specified=True
, secure=s_cookie['secure']
, expires=None
, discard=False
, comment=None
, comment_url=None
, rest=None
, rfc2109=False
)
)
opener = urllib2.build_opener(cp)
response = opener.open(url_that_requires_a_logged_in_user)
response.geturl()
0:
ben urllib2 içinde cooky kullanmak için birkaç farklı yol denedim, bence bu iyi görünüyorYine de çalışmıyor.
Bu son message.geturl() çağrısı, giriş sayfasını döndürür.
Bir şey mi eksik?
Sorunu aramaya nasıl başlayacağınıza dair herhangi bir fikir var mı?
Teşekkürler.
opener'den "cj" nedir? Urllib2.build_opener (urllib2.HTTPCookieProcessor (cj))? –
'cj = cp.cookiejar'. Asıl sorunun kodu içinde. – ronnefeldt