Jan-27-2019, 12:37 AM
Jan-27-2019, 01:00 AM
BeautifulSoup is for parsing HTML. What code did you use to get the error, and what is the error? What was the installation process?
Jan-27-2019, 01:04 AM
Explain better what you mean bye embedding HTML Code in Python?
BeautifulSoup is for web-scraping and not for embedding HTML Code.
Can in way embed HTML code with triple quote,when learning BS.
(Jan-27-2019, 12:37 AM)kendias Wrote: [ -> ]Tried importing Beautiful Soup but get error.What error?
BeautifulSoup is for web-scraping and not for embedding HTML Code.
Can in way embed HTML code with triple quote,when learning BS.
from bs4 import BeautifulSoup # Simulate a web page html = '''\ <body> <div id='images'> <a href='image1.html'>Name: My image 1 <br /><img src='image1_thumb.jpg' /></a> <a href='image2.html'>Name: My image 2 <br /><img src='image2_thumb.jpg' /></a> <a href='image3.html'>Name: My image 3 <br /><img src='image3_thumb.jpg' /></a> </div> </body>''' soup = BeautifulSoup(html, 'html.parser') print([link.get('href') for link in soup.find_all('a')])
Output:['image1.html', 'image2.html', 'image3.html']
Jan-27-2019, 01:15 AM
Here is my code. I am using Enthought Canopy. I get error invalid syntax on line 4 i.e.
<lat>
<lat>
from bs4 import BeautifulSoup soup = BeautifulSoup(xml, 'html.parser') lat = soup.find('latitude') <lat> <latitude>1.123123</latitude> </lat> print((lat.text))
Jan-27-2019, 01:33 AM
So my guess was correct,if look at my example code do you not see your error?
Can not just past in HTML code,have to put it in triple quote.
Can not just past in HTML code,have to put it in triple quote.
from bs4 import BeautifulSoup xml = '''\ <lat> <latitude>1.123123</latitude> </lat>''' soup = BeautifulSoup(xml, 'html.parser') lat = soup.find('latitude') print((lat.text))
Output:1.123123
Jan-27-2019, 01:43 AM
Thanks Snippsat. Works fine!