首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >机械化不能正确解析字段

机械化不能正确解析字段
EN

Stack Overflow用户
提问于 2011-10-24 22:00:10
回答 1查看 371关注 0票数 0

我开始在Rails中使用机械化,但它似乎不能正常工作,在表单中找不到字段。我试过使用机械化网站的例子,但它不起作用。我做了:

代码语言:javascript
复制
agent = Mechanize.new
page = agent.get('http://google.com/')

它返回:

代码语言:javascript
复制
=> #<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')返回:

代码语言:javascript
复制
=> #<Mechanize::Form
 {name "f"}
 {method "GET"}
 {action "/search"}
 {fields}
 {radiobuttons}
 {checkboxes}
 {file_uploads}
 {buttons}>

google_form.q = 'ruby mechanize'返回:

NoMethodError:未定义方法q=' for #<Mechanize::Form:0xb33e7070> from /usr/lib/ruby/gems/1.8/gems/mechanize-2.0.1/lib/mechanize/form.rb:162:inmethod_missing‘from (irb):23

我使用了机械化版本2.0.1和Nokogiri版本1.4.4、Ruby 1.8.7和Rails 3.1

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-24 22:19:58

使用散列访问变量设置字段:

代码语言:javascript
复制
google_form['q'] = 'ruby mechanize'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7882514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档