i want to get row which it contains more than 3 columns
how to write xpath with nokogiri
require 'rubygems'
require 'nokogiri'
item='sometext'
doc = Nokogiri::HTML.parse(open(item))
data=doc.xpath('/html/body/table/tr[@td.size>3]')
puts data
it can not run , help and advices appreciated.
On Fri, 27 Aug 2010 23:26:53 +0900, Pen Ttt wrote:
i want to get row which it contains more than 3 columns how to write
xpath with nokogiri
require 'rubygems'
require 'nokogiri'
item='sometext'
doc = Nokogiri::HTML.parse(open(item))
data=doc.xpath('/html/body/table/tr[@td.size>3]') puts data
it can not run , help and advices appreciated.
--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/
with the code ,
require 'rubygems'
require 'nokogiri'
doc = Nokogiri::HTML.parse(open('/home/pt/mytest'))
result=doc.xpath('//table/tr[*[not(@class="tickerSm")]]')
puts result
the row can not be selected by my code,
<tr bgcolor="F3F3F3">
<td align="right" width="240" class="tickerSm">reportdate</td>
<td align="right" width="65" class="tickerSm">10/31/09</td>
<td align="right" width="65" class="tickerSm">10/31/08</td>
<td align="right" width="65" class="tickerSm">10/31/07</td>
<td align="right" width="65" class="tickerSm">10/31/06</td>
<td align="right" width="65" class="tickerSm">10/31/05</td>
</tr>
<tr bgcolor="ffffff">
but how to delete row with xpath?
<tr bgcolor="ffffff">
<td class="tickerSm">Cash & Equivalents</td>
<td align="right" class="ticker">2,493</td>
<td align="right" class="ticker">1,429</td>
<td align="right" class="ticker">1,826</td>
<td align="right" class="ticker">2,262</td>
<td align="right" class="ticker">2,251</td>
</tr>
it can't work :
xpath('//table/tr[*[not(@class="tickerSm")]]')
maybe the reason is : some class of td is "ticker",another is
"tickerSm",
if i don't want to select it with xpath,how to express it with xpath??
p1
data=doc.xpath('/table/tr/*[count(td)>1]')
puts data
p2
data=doc.xpath('/table/tr/td[count(td)>1]')
puts data
none of them is right,why can i get nothing?
xpath('//table/tr[*[not(@class="tickerSm")]]')
maybe the reason is : some class of td is "ticker",another is
"tickerSm",
if i don't want to select it with xpath,how to express it with xpath??
Hi Pen,
I don't know if "not" is valid like that, I have to double check. But
you can use "!=" with attributes.
document.xpath("//*[count(td)=2]") is right,but i want to know
p1
data=doc.xpath('/table/tr/*[count(td)>1]')
puts data
p2
data=doc.xpath('/table/tr/td[count(td)>1]')
puts data
how to fix p1\p2?
but how can i get the following with xpath expression?
<tr bgcolor="ffffff">
<td class="tickerSm">Cash & Equivalents</td>
<td align="right" class="ticker">2,493</td>
<td align="right" class="ticker">1,429</td>
<td align="right" class="ticker">1,826</td>
<td align="right" class="ticker">2,262</td>
<td align="right" class="ticker">2,251</td>
</tr>
If the table is not the root or directly inside the root, you need 2
"/" in the beginning. The count function applies to the tr, not the
td, so you don't need the "*" in p1, or the td in p2. Try this:
doc.xpath('//table/tr[count(td)>1]')
Good Luck,
Ammar
···
On Sat, Aug 28, 2010 at 3:33 PM, Pen Ttt <myocean135@yahoo.cn> wrote:
document.xpath("//*[count(td)=2]") is right,but i want to know
p1
data=doc.xpath('/table/tr/*[count(td)>1]')
puts data
p2
data=doc.xpath('/table/tr/td[count(td)>1]')
puts data
how to fix p1\p2?
--
Posted via http://www.ruby-forum.com/\.