I have a big HTML file that was created merging several HTML files, so the structure is repeated N times <html>..</html> <html>..</html> like this:
<html>
<head>
<body>
<TABLE>
<TABLE>
</body>
</html>
<html>
<head>
<body>
<TABLE>
<TABLE>
</body>
</html>
<html>
<head>
<body>
<TABLE>
<TABLE>
</body>
</html>
A more complete example is here https://jsfiddle.net/28du1omt/
I'd like to extract all kinds of elements within the second table of each html block in order to get this:
I say all elements, since second table could have inside paragraphs, tables, images, http links, etc (<p>, <img>, <tables>, etc)
<html>
<head>
</head>
<body>
<p> </p>
<p><font size="5" color="red">some text file 1</font></p>
<p><font size="4" color="purple">some text file 1</font></p>
<p> </p>
<p>some text file 2</p>
<p> </p>
<p>some text file 3</p>
</body>
</html>
How can I do this?
My current code looks all tables elements within file but I don´t know how to extract only elements inside each second table of each html block.
from bs4 import BeautifulSoup
fp = open("file.html", "rb")
soup = BeautifulSoup(fp, "html5lib")
tables = soup.find_all('table')
for tbl in tables:
print(tbl.find_all())