简体   繁体   English

Ruby Nokogiri提取HTML选项卡值

[英]Ruby Nokogiri extract HTML tab value

there's a webpage with many pages. 网页很多。 And I'd like to know the total pages for each search. 而且,我想知道每次搜索的总页数。 Like the pictures shown below. 如下图所示。 Since the last page is page 41 and it becomes un_clickable. 由于最后一页是第41页,因此无法点击。 So I want to extract that value 41 from those 2 span tags. 所以我想从那两个span标签中提取值41。

Any help? 有什么帮助吗? I tried with xpath. 我尝试使用xpath。 But would prefer a CSS solution 但是更喜欢CSS解决方案

Thanks 谢谢

page_temp = Nokogiri::HTML(browser.html)  
page_temp.xpath('tr[@td = "colspan="32""]').each do |node|
    puts node.text

Click here to view the snapshot 点击此处查看快照

Since you are using Ruby here's a simple code you can use 由于您使用的是Ruby,因此您可以使用以下简单代码

page_temp = Nokogiri::HTML(browser.html)  
all_pages = page_temp.search("td[colspan='32'] tr td")
puts all_pages.map{|p| p.text}  # list all page numbers
puts all_pages.last.text        # list the last page number

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM