I am trying to webscrape some parts of this page: https://markets.businessinsider.com/stocks/bp-stock using BeautifulSoup to search for some text contained in h2 title of tables
when i do:
data_table = soup.find('h2', text=re.compile('RELATED STOCKS')).find_parent('div').find('table')
It correctly get the table I am after.
When I try to get the table "Analyst Opinion" using the similar line, it returns None:
data_table = soup.find('h2', text=re.compile('ANALYST OPINIONS')).find_parent('div').find('table')
I am guessing that there might be some special characters in the html code, that provides re to function as expected. I tried this too:
data_table = soup.find('h2', text=re.compile('.*?STOCK.*?INFORMATION.*?', re.DOTALL))
without success.
I would like to get the table that contain this bit of text "Analyst Opinion" without finding all tables but by checking if contains my requested text.
Any idea will be highly appreciated. Best
` with this command: `data_table = soup.find(lambda tag: tag.name=='h2' and re.findall(r'analyst opinion', tag.text, flags=re.I))`
– Andrej Kesely Aug 20 '19 at 18:25