Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BeautifulSoup: Find table by style

Is it possible to find a specific table with unique style?

Say, given the following html:

<table border="1" style="background-color:White;font-size:10pt;border-collapse:collapse;">

How can I use BS to find that table?

Thanks

like image 244
papercuts Avatar asked May 10 '14 18:05

papercuts


2 Answers

Try it:

from bs4 import BeautifulSoup
bs = BeautifulSoup(htmlcontent)
bs.find_all('table', attrs={'border': '1' ,'style':'background-color:White;font-size:10pt;border-collapse:collapse;'})

Check this link for more details.

like image 53
mortymacs Avatar answered Oct 26 '22 13:10

mortymacs


import requests
from bs4 import BeautifulSoup
r = requests.get("https://www.lipsum.com/")
soup =   BeautifulSoup(r.content,"lxml")
print(soup.find_all('div',style=lambda value: value and 'text-align:justify' in value))

Note: important use attrs for class !!!

like image 43
ihsan güç Avatar answered Oct 26 '22 14:10

ihsan güç