python填表格_使用python脚本填充表单

我正在尝试编写一个python脚本,它将填写一个网站上的表单,并发送它,然后在发送后,我想搜索结果网页上的关键字。在

当我在网上手动填写表格时,按“继续”按钮后,我得到一种“处理页面”,然后我得到了我想在其上搜索的网页关键字。在

我试图在这里使用脚本:http://stockrt.github.io/p/handling-html-forms-with-python-mechanize-and-BeautifulSoup/,但由于某些原因,在提交表单后,我这样做:print br.response().geturl()我得到了“处理页面”的url,而不是我要搜索的网页的url。在

我的代码:import mechanize

import cookielib

from BeautifulSoup import BeautifulSoup

import html2text

# Browser

br = mechanize.Browser()

# Cookie Jar

cj = cookielib.LWPCookieJar()

br.set_cookiejar(cj)

# Browser options

br.set_handle_equiv(True)

br.set_handle_gzip(True)

br.set_handle_redirect(True)

br.set_handle_referer(True)

br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0

br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# User-Agent (this is cheating, ok?)

br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

# The site we will navigate into, handling it's session

br.open('https://booking.elal.co.il/newBooking/changeOrder.jsp?LANG=EN&RESSYSTEMID=1')

# Select the first (index zero) form

br.select_form(nr=0)

# User credentials

br.form['REC_LOC'] = '...'

br.form['DIRECT_RETRIEVE_LASTNAME'] = '...'

# Login

br.submit()

#Trying to print the webpage

html = br.response().read()

print html2text.html2text(html)

我能做我想做的事吗?我该怎么做?在

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值