python html_在python中下载html?

我试图在您单击浏览器中的链接时下载通过

javascript操作请求的页面的html.我可以下载第一页,因为它有一个通用的URL:

http://www.locationary.com/stats/hotzone.jsp?hz=1

但是页面底部有一些链接是数字(1到10).因此,如果您点击一个,它会转到,例如,第2页:

http://www.locationary.com/stats/hotzone.jsp?ACTION_TOKEN=hotzone_jsp$JspView$NumericAction&inPageNumber=2

当我将该URL放入我的程序并尝试下载html时,它会在网站上显示不同页面的html,我认为它是主页.

如何获取使用javascript的此URL的html以及何时没有特定的URL?

谢谢.

码:

import urllib

import urllib2

import cookielib

import re

URL = ''

def load(url):

data = urllib.urlencode({"inUserName":"email", "inUserPass":"password"})

jar = cookielib.FileCookieJar("cookies")

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

opener.addheaders.append(('User-agent', 'Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20100101 Firefox/13.0.1'))

opener.addheaders.append(('Referer', 'http://www.locationary.com/'))

opener.addheaders.append(('Cookie','site_version=REGULAR'))

request = urllib2.Request("https://www.locationary.com/index.jsp?ACTION_TOKEN=tile_loginBar_jsp$JspView$LoginAction", data)

response = opener.open(request)

page = opener.open("https://www.locationary.com/index.jsp?ACTION_TOKEN=tile_loginBar_jsp$JspView$LoginAction").read()

h = response.info().headers

jsid = re.findall(r'Set-Cookie: (.*);', str(h[5]))

data = urllib.urlencode({"inUserName":"email", "inUserPass":"password"})

jar = cookielib.FileCookieJar("cookies")

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

opener.addheaders.append(('User-agent', 'Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20100101 Firefox/13.0.1'))

opener.addheaders.append(('Referer', 'http://www.locationary.com/'))

opener.addheaders.append(('Cookie','site_version=REGULAR; ' + str(jsid[0])))

request = urllib2.Request("https://www.locationary.com/index.jsp?ACTION_TOKEN=tile_loginBar_jsp$JspView$LoginAction", data)

response = opener.open(request)

page = opener.open(url).read()

print page

load(URL)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值