Python 3.x Python+;Mechanize-使用POST模拟Javascript按钮单击?
我正在尝试在网站上自动填写汽车保险报价表: (使用与站点URL相同的格式进行调用:”https://secure.examplesite.com/css/car/step1#noBack)) 我被困在rego部分,因为一旦添加了rego,就需要单击一个按钮来执行搜索,这似乎是一个繁重的Javascript,我知道mechanizer无法处理这个问题。我不精通JavaScript,但我可以看到,当单击按钮时,会向此URL发出POST请求:(“https://secure.examplesite.com/css/car/step1/searchVehicleByRegNo)请参见图片 如何在Mechanize中模拟此POST请求以运行javascript?所以我可以看到反应/与反应互动?或者这是不可能的?我可以考虑BS4/Reope/RooBuffor。我学习才4个月!谢谢Python 3.x Python+;Mechanize-使用POST模拟Javascript按钮单击?,python-3.x,forms,post,mechanize,mechanize-python,Python 3.x,Forms,Post,Mechanize,Mechanize Python,我正在尝试在网站上自动填写汽车保险报价表: (使用与站点URL相同的格式进行调用:”https://secure.examplesite.com/css/car/step1#noBack)) 我被困在rego部分,因为一旦添加了rego,就需要单击一个按钮来执行搜索,这似乎是一个繁重的Javascript,我知道mechanizer无法处理这个问题。我不精通JavaScript,但我可以看到,当单击按钮时,会向此URL发出POST请求:(“https://secure.examplesite.c
# Mechanize test
import mechanize
br = mechanize.Browser()
br.set_handle_robots(False) # ignore robots
br.set_handle_refresh(False) # can sometimes hang without this
res = br.open("https://secure.examplesite.com/css/car/step1#noBack")
br.select_form(id = "quoteCollectForm")
br.set_all_readonly(False) # allow everything to be written to
controlDict = {}
# List all form controls
for control in br.form.controls:
controlDict[control.name] = control.value
print("type = %s, name = %s, value = %s" %(control.type, control.name, control.value))
# Enter Rego etc "example"
br.form["vehicle.searchRegNo"] = "example"
# Now for control name = vehicle.searchRegNo, value = example
# BUT Now how do I click the button?? Simulate POST? The post url is formatted like:
# https://secure.examplesite.com/css/car/step1/searchVehicleByRegNo
解决了我自己的问题-
步骤: