【发布时间】:2013-07-19 18:28:28
【问题描述】:
我正在开发一个从 http://www.screener.in/ 获取 HTML 的应用程序。
我可以输入像“Atul Auto Ltd”这样的公司名称并提交它,从the next page, 抓取以下详细信息:“CMP/BV”和“CMP”。
我正在使用此代码:
require 'mechanize'
require 'rubygems'
require 'nokogiri'
Company_name='Atul Auto Ltd.'
agent = Mechanize.new
page = agent.get('http://www.screener.in/')
form = agent.page.forms[0]
print agent.page.forms[0].fields
agent.page.forms[0]["q"]=Company_name
button = agent.page.forms[0].button_with(:value => "Search Company")
pages=agent.submit(form, button)
puts pages.at('.//*[@id="top"]/div[3]/div/table/tbody/tr/td[11]')
# not getting any output.
代码将我带到正确的页面,但我不知道如何查询以获取所需的数据。
我尝试了不同的方法,但没有成功。
如果可能的话,有人能指点我一个很好的教程,它解释了如何从 HTML 页面中抓取特定的类。 第一个“CMP/BV”的 XPath 是:
//*[@id="top"]/div[3]/div/table/tbody/tr/td[11]
但它没有给出任何输出。
【问题讨论】:
标签: ruby nokogiri mechanize mechanize-ruby