Hello其他程序员。我正在尝试自动化用于购买的网站。购买页面加载速度非常慢。加载后,使用ajax调用查询。我想要做的是加载页面,获取数据,确定是否有任何项目符合我的标准,如果是,返回主页面,选择我想要购买的项目,然后购买。
我的问题是back()
方法很慢。它怀疑它正在重新加载页面。
有没有办法让它从缓存中访问该页面?或许,一种在不离开主页的情况下进行ajax调用的方法?
import mechanize
import datetime
br = mechanize.Browser()
br.set_handle_robots(False)
print(str(datetime.datetime.now()) + " logging in")
br.open("https://www.somesite.com/login.action")
br.select_form(nr=0)
br['login_email'] = "userId"
br['login_password'] = "password"
rs = br.submit()
print(str(datetime.datetime.now()) + " opening slow page")
rs = br.open("https://www.somesite.com/veryslow.action")
print(str(datetime.datetime.now()) + " getting data")
json = br.open("https://www.somesite.com/getDataAj.action")
print(str(datetime.datetime.now()) + " clicking back")
br.back()
print(str(datetime.datetime.now()) + " returned to slow loading page")
#more to do on page... fill out form, submit()
br.open("https://www.somesite.com/logout.action")
print(str(datetime.datetime.now()) + " logged out")
结果,请注意back()
花了多长时间:
2013-05-17 13:14:55.650000 logging in
2013-05-17 13:14:58.678000 opening slow page
2013-05-17 13:15:17.158000 getting data
2013-05-17 13:15:18.207000 clicking back
2013-05-17 13:15:29.592000 returned to slow loading page
2013-05-17 13:15:30.120000 logged out