我想登录此网站:https://www.netflix.com/login。我在验证登录是否成功时遇到问题。我尝试使用if ... in ..条件但它仍然不起作用,所以我评论了它。这是我使用的代码:
import urllib
import urllib2
from cookielib import CookieJar
import re
#creating a opener that that will allow us to open webpage
#and save all session and cookie information in the jar
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
res = opener.open('https://www.netflix.com/Login')
data = res.read()
results = re.search('name="authURL".*?value="(?P<authURL>.*?)"', data)
authURL = results.group('authURL')
formValues = {
"email" : "***********",
"password" : "*****",
'authURL': authURL
}
#encode these value so python can subbmit in http request
#so server can udnerstand
data = urllib.urlencode(formValues)
response = opener.open("https://www.netflix.com/Login?locale=en-US", data)
#m = re.search('Sorry, we are unable to process your request. Please try again later.', response.read())
#if m:
# print "Log in failed!"
#if 'signup' in response.url:
# print "Login failed. Not sure why"