需要发布到现有网页(无需登录)并发布参数以进行提交,其中存在多个提交表单标签并包含具有相同 NAME 和 VALUE 标签的相同标签;例如,在同一页面上,此 INPUT Submit 在不同的 FORM 标记下重复 3 次:
< INPUT TYPE='Submit' NAME='submit_button' VALUE='Submit Query' >
我的 Ruby 代码可以正常运行以识别表单标签上的字段,但在 page.forms[x].action 帖子上失败, https : //pdb.nipr.com/html/PacNpnSearch 出现 405 HTTPMethodNotAllowed - 未处理的响应。
红宝石代码:
class PostNIPR2
def post(url)
button_count = 0
agent = Mechanize.new
page = agent.get(url)
page.forms.each do |form|
form.buttons.each do |button|
if(button.value == 'Submit Query')
button_count = button_count + 1
if (button_count == 3)
btn_submit_license = button.name
puts button
puts btn_submit_license
puts button.value
end
end
end
end
begin
uform = page.forms[1]
uform.license = "0H20649"
uform.state = "CA"
uform.action = 'https://pdb.nipr.com/html/PacNpnSearch'
rescue Exception => e
error_page = e.page
end
page = agent.submit(uform)
end
url = "https://pdb.nipr.com/html/PacNpnSearch.html"
p = PostNIPR2.new
p.post(url)
end