By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,172 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,172 IT Pros & Developers. It's quick & easy.

parse the html to get tr in python

P: 18
please download the attachments ,save as /tmp/A,run the following code,
Expand|Select|Wrap|Line Numbers
  1. import lxml.html
  2. sfile='/tmp/A'
  3. root=lxml.html.parse(sfile)
  4. t = root.xpath("//table[@class='yfnc_datamodoutline1']")
  5. trs=t.xpath(".//tr")
  6. for  i, tr  in  enumerate(trs):
  7.     print i, len(tr),tr.text_content()
  8.  
  9.  
the output is:
0 1 StrikeSymbolLastChgBidAskVolOpen Int20.00A110917C0002000016.90 0.0015.4018.9501023.00A110917C0002300011.05 0.0013.2515.3501128.00A110917C000280004.70 0.008.159.20122829.00A110917C000290003.80 0.006.709.60041330.00A110917C000300004.85 0.007.007.10339131.00A110917C000310002.07 0.005.606.151519432.00A110917C000320005.090.764.85 5.10894833.00A110917C000330002.82 0.003.554.1062,39434.00A110917C000340003.061.792.9 93.205240735.00A110917C000350001.950.141.792.14701 ,42336.00A110917C000360001.000.181.141.22212,24237 .00A110917C000370000.460.050.460.503731,70238.00A1 10917C000380000.130.070.120.141082,09439.00A110917 C000390000.07 0.000.020.077259940.00A110917C000400000.11 0.000.040.067278641.00A110917C000410000.09 0.00N/A0.0520059142.00A110917C000420000.22 0.00N/A0.05017943.00A110917C000430000.01 0.00N/A0.05148544.00A110917C000440000.09 0.00N/A0.0502,59045.00A110917C000450000.07 0.00N/A0.0501,10046.00A110917C000460000.22 0.00N/A0.05055747.00A110917C000470000.02 0.00N/A0.01028448.00A110917C000480000.15 0.00N/A0.05031149.00A110917C000490000.01 0.00N/A0.05036550.00A110917C000500000.03 0.00N/A0.052061552.50A110917C000525000.03 0.00N/A0.05022855.00A110917C000550000.01 0.00N/A0.05084
1 8 StrikeSymbolLastChgBidAskVolOpen Int
2 8 20.00A110917C0002000016.90 0.0015.4018.95010
3 8 23.00A110917C0002300011.05 0.0013.2515.35011


i don't understand when i=0 the tr.text_content() is :
StrikeSymbolLastChgBidAskVolOpen Int20.00A110917C0002000016.90 0.0015.4018.9501023.00A110917C0002300011.05 0.0013.2515.3501128.00A110917C000280004.70 0.008.159.20122829.00A110917C000290003.80 0.006.709.60041330.00A110917C000300004.85 0.007.007.10339131.00A110917C000310002.07 0.005.606.151519432.00A110917C000320005.090.764.85 5.10894833.00A110917C000330002.82 0.003.554.1062,39434.00A110917C000340003.061.792.9 93.205240735.00A110917C000350001.950.141.792.14701 ,42336.00A110917C000360001.000.181.141.22212,24237 .00A110917C000370000.460.050.460.503731,70238.00A1 10917C000380000.130.070.120.141082,09439.00A110917 C000390000.07 0.000.020.077259940.00A110917C000400000.11 0.000.040.067278641.00A110917C000410000.09 0.00N/A0.0520059142.00A110917C000420000.22 0.00N/A0.05017943.00A110917C000430000.01 0.00N/A0.05148544.00A110917C000440000.09 0.00N/A0.0502,59045.00A110917C000450000.07 0.00N/A0.0501,10046.00A110917C000460000.22 0.00N/A0.05055747.00A110917C000470000.02 0.00N/A0.01028448.00A110917C000480000.15 0.00N/A0.05031149.00A110917C000490000.01 0.00N/A0.05036550.00A110917C000500000.03 0.00N/A0.052061552.50A110917C000525000.03 0.00N/A0.05022855.00A110917C000550000.01 0.00N/A0.05084

why??
Attached Files
File Type: txt A.txt (86.3 KB, 524 views)
Sep 23 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.