How to retrieve value from td which under table/tbody/tr by python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: How to retrieve value from td which under table/tbody/tr by python (/thread-27991.html) |
How to retrieve value from td which under table/tbody/tr by python - DDNEW - Jun-30-2020
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: print(td.text) print(tds[2]) print(tds[6])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 ) thank you very much RE: How to retrieve value from td which under table/tbody/tr by python - Larz60+ - Jun-30-2020 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 = table.tr.find_all('td) for n, td in enumerate(tds): print(f"index {n}: {td.text.strip()}") |