Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to retrieve value from td which under table/tbody/tr by python
<table id="table-orders" cellpadding="0" cellspacing="0" border="0" class="mypage_table"> <colgroup> <col width="13%"> <col width="5%"> <col width="10%"> <col width="10%"> <col width="15%"> <col width="2%"> <col width="15%"> <col width="15%"> <col width="15%"> </colgroup> <thead> <tr style="cursor: default;"> <th colspan="2"><nobr>H1</nobr></th> <th><nobr>H2</nobr></th> <th><nobr>H3</nobr></th> <th colspan="3"><nobr>H4</nobr></th> <th><nobr>H5</nobr></th> <th><nobr>H6</nobr></th> </tr> </thead> <tbody> <tr data-idx="531006" data-no="AP86F561ED" data-type="AP"> <td><span class="btn btn-block badge" style="width: 85%; background-color: #CD0001; color: #FFFFFF;">B1</span></td> <td><nobr><img src="/images/common/ft_text.png" width="16" height="16">&nbsp;/&nbsp;<img src="/images/common/ft_file.png" width="16" height="16"></nobr></td> <td style="text-align:right;">0.5 HR</td> <td>B3</td> <td style="text-align:right;">B4</td> <td>B5</td> <td style="text-align:left;">B6</td> <td style="text-align:left;">B7</td> <td style="text-align:right;">B8</td> </tr> </tbody> </table>
   html = driver.page_source
    soup = BeautifulSoup(html,'html.parser')

    table = soup.find('table', id="table-orders")
    rows = table.findAll('tr')

    for tr in soup.find_all('table', id='table-orders'):
        tds = tr.find_all('td') 
        for td in tds:
I only need to get this one [ <td style="text-align:right;">0.5 HR</td>]
because I want to know if this value bigger than 5
can you teach me how to get it and replace HR ? ( my code return error Cry )
thank you very much
Larz60+ wrote Jun-30-2020, 05:02 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.

Note: Output tags work for input as well
Since you've made a good effort (this is untested code, so up to you to try and repair if necessary):
Also you will need to get the proper row. This code will peint all, with index
html = driver.page_source
soup = BeautifulSoup(html,'html.parser')
table = soup.find('tbody', {'data-no': 'AP86F561ED'})
tds ='td)
for n, td in enumerate(tds):
    print(f"index {n}: {td.text.strip()}")

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)