I'm currently trying to scrape text from webpages using Python 2.7's BeautifulSoup (bs4). My original code is as follows:
string = ''
a = soup.find('div',attrs={"id":"pressrelease"})
[x.extract() for x in a.findAll('script')]
[x.extract() for x in a.findAll("span", {'class':'hidden'})]
for element in a:
try:
string += element.get_text()
except Exception as e: print(e)
Although my code does get me the desired text, it also spits out the following error: 'NavigableString' object has no attribute 'get_text'. I want to implement a feature that saves the URL if the code hits an exception but in this case, I don't want the URL saved since even though it's throwing an exception the page was successfully scraped. Thus, I am trying to better understand what the error exactly is (so I can decide whether to purposefully ignore this case).
Any explanations on what a navigablestring is and why it would cause my code to throw such an error would be much appreciated!