Can You Find The Parent Of The Soup In Beautifulsoup
I am working with beautiful soup in python, and I am working on a project that retrieves my school schedule. It's a badly written website. It is a HTML table, with every cell conta
Solution 1:
You can find a tags parent by calling the .parent
attribute.
...
print(soup.find('table').parent)
Edit: Try using the find_previous()
method:
>>>html = """...<td colspan="12" rowspan="4" align="center">... <table>... <tr><td>*data is here*</td></tr>...""">>>soup = BeautifulSoup(html, "html.parser")>>>>>>for tag in soup.find_all("table"):...print(tag.find_previous("td")["rowspan"])...
4
>>>
Post a Comment for "Can You Find The Parent Of The Soup In Beautifulsoup"