Last active
November 1, 2025 03:45
-
-
Save raspberrypisig/d3cb39e798ddbd20a4ca3d2ab549da2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| def bs4demo(): | |
| html = """ | |
| <table> | |
| <tr> | |
| <th>Name</th> | |
| <th>Age</th> | |
| </tr> | |
| <tr> | |
| <td>Alice</td> | |
| <td>30</td> | |
| </tr> | |
| <tr> | |
| <td>Bob</td> | |
| <td>25</td> | |
| </tr> | |
| </table> | |
| """ | |
| soup = BeautifulSoup(html, "html.parser") | |
| rows = soup.select("tr") | |
| for row in rows: | |
| cells = [td.text for td in row.select("td")] | |
| if len(cells) > 0: | |
| print(cells) | |
| if __name__ == "__main__": | |
| bs4demo() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <table> | |
| <tr> | |
| <th>Name</th> | |
| <th>Age</th> | |
| </tr> | |
| <tr> | |
| <td>Alice</td> | |
| <td>30</td> | |
| </tr> | |
| <tr> | |
| <td>Bob</td> | |
| <td>25</td> | |
| </tr> | |
| </table> | |
| </body> | |
| </html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment