相关疑难解决方法(0)

使用Ruby/Mechanize(和Nokogiri)从HTML中提取单个字符串

我正从论坛中提取数据.我的脚本基于工作正常.现在我需要从单个帖子中提取日期和时间(2009年12月21日,20:39).我无法让它发挥作用.我使用FireXPath来确定xpath.

示例代码:

 require 'rubygems'
 require 'mechanize'

   post_agent = WWW::Mechanize.new
    post_page = post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')
    puts  post_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div[2]/text()').to_s.strip
    puts  post_page.parser.at_xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div[2]/text()').to_s.strip
    puts post_page.parser.xpath('//[@id="post1960370"]/tbody/tr[1]/td/div[2]/text()')
Run Code Online (Sandbox Code Playgroud)

我的所有尝试都以空字符串或错误结束.


我找不到有关在Mechanize中使用Nokogiri的任何文档.Mechanize文档在页面底部显示:

使用Mechanize导航到需要刮擦的页面后,使用Nokogiri方法刮取它.

但有什么方法呢?我在哪里可以通过样本和解释语法阅读它们?我也没有在Nokogiri的网站上找到任何东西.

ruby parsing information-extraction nokogiri

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

information-extraction ×1

nokogiri ×1

parsing ×1

ruby ×1