机械化无法通过行动找到形式
Mechanize can't find form by action
我有以下代码
mechanize = Mechanize.new do |agent|
agent.user_agent_alias = 'Windows Chrome'
end
page = mechanize.get("https://sports.bwin.com/en/sports#leagueIds=6004&sportId=7")
puts page.body
form = page.form_with(:action => "/en/sports/indexmultileague")
pp form
我可以从 puts page.body 的输出中看到 html 中存在一个包含我要查找的操作的表单,但是 pp 表单只打印 nil
当我查看页面源代码时,我无法看到带有该操作的表单。
但是,使用 Chrome 检查器工具(显示动态内存页面源),我能够看到该表单。
这意味着表单是通过脚本动态生成的,Mechanize
不支持脚本。
您将需要使用支持脚本的网络驱动程序。
例如,如果您使用的是 Selenium,则可以查看表单部分 here。
您可以深入研究 Selenium's documentation 以准确了解您正在尝试做的事情。
我有以下代码
mechanize = Mechanize.new do |agent|
agent.user_agent_alias = 'Windows Chrome'
end
page = mechanize.get("https://sports.bwin.com/en/sports#leagueIds=6004&sportId=7")
puts page.body
form = page.form_with(:action => "/en/sports/indexmultileague")
pp form
我可以从 puts page.body 的输出中看到 html 中存在一个包含我要查找的操作的表单,但是 pp 表单只打印 nil
当我查看页面源代码时,我无法看到带有该操作的表单。
但是,使用 Chrome 检查器工具(显示动态内存页面源),我能够看到该表单。
这意味着表单是通过脚本动态生成的,Mechanize
不支持脚本。
您将需要使用支持脚本的网络驱动程序。
例如,如果您使用的是 Selenium,则可以查看表单部分 here。
您可以深入研究 Selenium's documentation 以准确了解您正在尝试做的事情。