Tag objects in Beautiful Soup

Denis McMahon denismfmcmahon at gmail.com
Thu Nov 20 17:49:42 EST 2014


On Thu, 20 Nov 2014 06:31:08 -0800, Simon Evans wrote:

> Can anyone tell me where I am going wrong or where the text is wrong ?
> So far the given code has run okay, I have put to the console everything
> the text tells you to. Thank you for reading.
> Simon Evans

Having looked at the ebook, there seems to be an error in the book. 
Unfortunately I'm not 100% sure what the error is.

However, it may be that:

atag = soup_atag.a

is meant to be:

atag = soup.a

There are also errors in the html itself in the ebook, the href of each 
of the urls is quoted as href="....' (mixing single and double quotes) 
and one of the urls has a semi-colon where a colon is expected, these 
seem to throw the parser.

These errors also appear in your html snippet:

html_atag = """<html><body><p>Test html a tag example</p>

<a href="http://www.packtpub.com'>Home</a>
........^.......................^

<a href="http;//www.packtpub.com/books'.Books</a>
........^....^........................^

</body>
</html>"""

In addition to these errors in the source html, you seem to have replaced 
a '>' with a '.' on the second anchor tag in the html.

<a href="http;//www.packtpub.com/books'.Books</a>
.......................................^

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list