同一域下的Python pycurl 4端点返回相同的数据

时间:2018-08-14 17:56:58

标签: python pycurl

我有一个远程主机,我用pycurl来获取某些数据。 1.我必须通过表单登录才能开始有效的会话。 2.获得有效的会话后,可以通过其他URL请求数据。

我遇到的问题是,不同的URL会产生相同的结果。 content_url <1-3>应该产生不同的数据。如果我使用浏览器交互,则content_urls会给我带来与预期不同的结果。请让我知道我在想什么或做错了什么。以下是我的代码段:

buf = StringIO.StringIO()
c = pycurl.Curl()
login_fields = 'username=xxxx&password=xxxx'
c.setopt(c.URL,'remote_ip_address/login.html')
c.setopt(c.COOKIEJAR,'cookies.txt')
c.setopt(c.COOKIEFILE,'cookies.txt')
c.setopt(c.POSTFIELDS,login_fields)
c.setopt(c.VERBOSE, True)
c.setopt(c.FOLLOWLOCATION,True)
try:
    content_url1 = 'content1.dat'
    #content_url2 = 'content2.dat'
    #content_url3 = 'content3.dat'
    c.perform()
    c.setopt(c.HTTPGET,True)
    c.setopt(c.URL,'remote_ip_address/' + content_url1)
    c.setopt(c.COOKIEFILE,'cookies.txt')
    c.setopt(c.WRITEFUNCTION, buf.write)
    c.setopt(c.VERBOSE, True)
    c.perform()
    print "Content Data " + buf.getvalue()
    try:
        #log out
        logout_fields = 'sessionid=sessionid'
        c.setopt(c.URL,'ip_address/logout.html')
        c.setopt(c.COOKIEFILE,'cookies.txt')
        c.setopt(c.POSTFIELDS,logout_fields)
        c.setopt(c.VERBOSE, True)
        c.perform()
        c.close()
        buf.close()
    except Exception, e:
        print e
except Exception, e:
    print e

0 个答案:

没有答案