Python 302谷歌AJAX页面重定向

Python 302谷歌AJAX页面重定向,python,ajax,urllib2,Python,Ajax,Urllib2,我试图从没有API的谷歌经销商面板上获取数据 我能够使用urllib2和cookiejar成功登录,并且可以看到安全的数据,但是我需要的数据是用AJAX加载的 当我尝试直接访问AJAX端点时,会得到302或404重定向。有什么想法吗 这是我的密码: import cookielib, urllib2, urllib, re, pprint cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookiePr

我试图从没有API的谷歌经销商面板上获取数据

我能够使用urllib2和cookiejar成功登录,并且可以看到安全的数据,但是我需要的数据是用AJAX加载的

当我尝试直接访问AJAX端点时,会得到302或404重定向。有什么想法吗

这是我的密码:

import cookielib, urllib2, urllib, re, pprint


cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [
    ('User-Agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11'),
    ]


# Define URLs (borrowed this from Google voice script on Github)
login_page_url = 'https://accounts.google.com/ServiceLogin?service=grandcentral'
authenticate_url = 'https://accounts.google.com/ServiceLoginAuth?service=grandcentral'
gv_home_page_url = 'https://www.google.com/voice/#inbox'

# Load sign in page
login_page_contents = opener.open(login_page_url).read()

# Find GALX value
galx_match_obj = re.search(r'name="GALX"\s*value="([^"]+)"', login_page_contents, re.IGNORECASE)

galx_value = galx_match_obj.group(1) if galx_match_obj.group(1) is not None else ''

# Set up login credentials
login_params = urllib.urlencode({
    'Email' : "<my username>",
    'Passwd' : "<my password>",
    'continue' : 'https://www.google.com/voice/account/signin',
    'GALX': galx_value
})

# Login
opener.open(authenticate_url, login_params)

# Open GV home page
gv_home_page_contents = opener.open(gv_home_page_url).read()

# Fine _rnr_se value
key = re.search('name="_rnr_se".*?value="(.*?)"', gv_home_page_contents)

if not key:
    logged_in = False
else:
    logged_in = True
    print "Logged in!"

    reseller_home = opener.open("https://www.google.com/a/cpanel/<my reseller domain>/Reseller2Customers#Reseller2Customers")
    print reseller_home.read() #prints data behind the login, http status code 200

    opener.addheaders += [
    ('Referer', 'https://www.google.com/a/cpanel/<my reseller domain>/Reseller2Customers'),
    ]


    reseller_ajax = opener.open("https://www.google.com/a/cpanel/<my reseller domain>/Reseller/GetSubscriptions?sortField=CREATION_DATE&sortAscending=true&nextToken=&customerDomainPrefix=covision.com").read()
    #this gives me error 302 or 404
导入cookielib、urllib2、urllib、re、pprint cj=cookielib.CookieJar() opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) opener.addheaders=[ (“用户代理”、“Mozilla/5.0(Macintosh;U;英特尔Mac OS X 10.6;en-US;rv:1.9.2.11)Gecko/20101012 Firefox/3.6.11”), ] #定义URL(从Github上的Google语音脚本中借用) 登录页面https://accounts.google.com/ServiceLogin?service=grandcentral' 验证https://accounts.google.com/ServiceLoginAuth?service=grandcentral' gv_主页\u url='1!'https://www.google.com/voice/#inbox' #加载登录页 login\u page\u contents=opener.open(login\u page\u url.read()) #求GALX值 galx_match_obj=re.search(r'name=“galx”\s*value=“([^”]+)”,登录页面内容,re.IGNORECASE) galx_值=galx_匹配对象组(1),如果galx_匹配对象组(1)不是其他组“” #设置登录凭据 login_params=urllib.urlencode({ “电子邮件”:“, “Passwd”:“, “继续”:https://www.google.com/voice/account/signin', “GALX”:GALX_值 }) #登录 opener.open(验证url、登录参数) #打开GV主页 gv_home_page_contents=opener.open(gv_home_page_url).read() #精细值 key=re.search('name=“\r\u se.”*?value=“(.*)”,gv\u主页内容) 如果不是关键点: 登录=错误 其他: 已登录=真 打印“已登录!" 转销商_home=opener.open(“https://www.google.com/a/cpanel//Reseller2Customers#Reseller2Customers") print Rebeller_home.read()#打印登录后的数据,http状态代码200 opener.addheaders+=[ ('Referer','https://www.google.com/a/cpanel//Reseller2Customers'), ] 分销商\u ajax=opener.open(“https://www.google.com/a/cpanel//Reseller/GetSubscriptions?sortField=CREATION_DATE&sortAscending=true&nextToken=&customerDomainPrefix=covision.com)改为 #这给了我错误302或404
有关重定向本身的详细信息?什么时候有302,什么时候有404,有什么区别?在浏览器中有相同的重定向吗?有没有使用HTTP调试器(Firebug中的网络面板、Chrome developer tools中的网络面板等)跟踪标题?