gpt4 book ai didi

ruby - Mechanize 无法正确解析字段

转载 作者:行者123 更新时间:2023-12-04 16:20:57 25 4
gpt4 key购买 nike

我开始在 Rails 中使用 mechanize,但似乎它不能正常工作,它不会在表单中找到字段。我尝试使用 Mechanize 网站上的示例,但它不起作用。我做了:

agent = Mechanize.new
page = agent.get('http://google.com/')

它返回:
=> #<Mechanize::Page
{url #<URI::HTTP:0xb340ba74 URL:http://www.google.by/>}
{meta_refresh}
{title "Google"}
{iframes}
{frames}
{links
#<Mechanize::Page::Link
"Выявы"
"http://www.google.by/imghp?hl=be&tab=wi">
#<Mechanize::Page::Link
"Пераклад"
"http://translate.google.by/?hl=be&tab=wT">
#<Mechanize::Page::Link
"Групы"
"http://groups.google.by/grphp?hl=be&tab=wg">
#<Mechanize::Page::Link
"Гісторыя пошуку"
"http://www.google.com/history/optout?hl=be">
#<Mechanize::Page::Link "Наладкі" "/preferences?hl=be">
#<Mechanize::Page::Link
"Увайсьці"
"https://www.google.com/accounts/ServiceLogin?hl=be&continue=http://www.google.by/">
#<Mechanize::Page::Link
"Пашыраны пошук"
"/advanced_search?hl=be">
#<Mechanize::Page::Link "Language tools" "/language_tools?hl=be">
#<Mechanize::Page::Link
"русском"
"http://www.google.by/setprefs?sig=0_U7jPRU_lW24j6EjPs4nuN1IxPcM=&hl=ru">
#<Mechanize::Page::Link "Усё пра Google" "/intl/be/about.html">
#<Mechanize::Page::Link "Google.com in English" "http://www.google.com/ncr">}
{forms
#<Mechanize::Form
{name "f"}
{method "GET"}
{action "/search"}
{fields}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons}>}>
page.form('f')返回:
=> #<Mechanize::Form
{name "f"}
{method "GET"}
{action "/search"}
{fields}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons}>
google_form.q = 'ruby mechanize'返回:

NoMethodError: undefined method q=' for #<Mechanize::Form:0xb33e7070>
from /usr/lib/ruby/gems/1.8/gems/mechanize-2.0.1/lib/mechanize/form.rb:162:in
method_missing' from (irb):23



我使用 Mechanize 2.0.1 版和 Nokogiri 1.4.4 版、Ruby 1.8.7 和 Rails 3.1

最佳答案

使用哈希访问变量设置字段:

google_form['q'] = 'ruby mechanize'

关于ruby - Mechanize 无法正确解析字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7882514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com