Extracting a row from a table from a url
Question: I want to download EPS value for all years (Under Annual Trends) from the
below link. [http://www.bseindia.com/stock-share-
price/stockreach_financials.aspx?scripcode=500180&expandable=0](http://www.bseindia.com/stock-
share-price/stockreach_financials.aspx?scripcode=500180&expandable=0)

I tried using Beautiful Soup as mentioned in the below answer. [Extracting
table contents from html with python and
BeautifulSoup](http://stackoverflow.com/questions/17196018/extracting-table-
contents-from-html-with-python-and-beautifulsoup) But couldn't proceed after
the below code. I feel I am very close to my answer. Any help will be greatly
appreciated.

    
    
    from bs4 import BeautifulSoup
    import urllib2
    html = urllib2.urlopen("http://www.bseindia.com/stock-share-price/stockreach_financials.aspx?scripcode=500180&expandable=0").read()
    soup=BeautifulSoup(html)
    table = soup.find('table',{'id' :'acr'})
    #the below code wasn't working as I expected it to be
    tr = table.find('tr', text='EPS')
    

I am open to using any other language to get this done


Answer: The text is in the _td_ not the _tr_ so get the _td_ using the text and then
call _.parent_ to get the _tr_ :

    
    
    In [12]: table = soup.find('table',{'id' :'acr'})
    
    In [13]: tr = table.find('td', text='EPS').parent
    
    In [14]: print(tr)
    <tr><td class="TTRow_left" style="padding-left: 30px;">EPS</td><td class="TTRow_right">48.80</td>
    <td class="TTRow_right">42.10</td>
    <td class="TTRow_right">35.50</td>
    <td class="TTRow_right">28.50</td>
    <td class="TTRow_right">22.10</td>
    </tr>
    In [15]: [td.text for td in tr.select("td + td")]
    Out[15]: [u'48.80', u'42.10', u'35.50', u'28.50', u'22.10']
    

Which you will see exactly matches what is on the page.

Another approach would be to call _find_next_siblings_ :

    
    
    In [17]: tds = table.find('td', text='EPS').find_next_siblings("td")
    
    In [18]: tds
    Out[19]: 
    [<td class="TTRow_right">48.80</td>,
     <td class="TTRow_right">42.10</td>,
     <td class="TTRow_right">35.50</td>,
     <td class="TTRow_right">28.50</td>,
     <td class="TTRow_right">22.10</td>]
    In [20]: [td.text for td in tds]
    Out[20]: [u'48.80', u'42.10', u'35.50', u'28.50', u'22.10']
    

