parse html:what is the meaning of "//"?
alias
1248283536 at qq.com
Fri Sep 16 02:39:28 EDT 2011
code1:
import lxml.html
import urllib
down='http://finance.yahoo.com/q/op?s=C+Options'
content=urllib.urlopen(down).read()
root=lxml.html.document_fromstring(content)
table = root.xpath("//table[@class='yfnc_mod_table_title1']")[0]
tds=table.xpath("tr[@valign='top']//td")
for td in tds:
print td.text_content()
what i get is :
Call Options
Expire at close Friday, September 16, 2011
these are waht i want.
code2
import lxml.html
import urllib
down='http://finance.yahoo.com/q/op?s=C+Options'
content=urllib.urlopen(down).read()
root=lxml.html.document_fromstring(content)
table = root.xpath("//table[@class='yfnc_mod_table_title1']")[0]
tds=table.xpath("//tr[@valign='top']//td")
for td in tds:
print td.text_content()
what i get is :
N/A
N/A
2
114
48.00
C110917P00048000
16.75
0.00
N/A
N/A
0
23
50.00
C110917P00050000
23.16
0.00
N/A
N/A
115
2,411
Highlighted options are in-the-money.
(omit something)
there is only one difference between code1 and code2 :
in code1 is : tds=table.xpath("tr[@valign='top']//td")
in code2 is: tds=table.xpath("//tr[@valign='top']//td")
i want to know why the "//" make output different?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110916/dd5b4c78/attachment.html>
More information about the Python-list
mailing list