I wish to extract the second link (that is the link for the number '2') from the following HTML code:
<div class="post-footers"> 1 |<a href="index.html?page=2"> 2 </a>|<a href="index.html?page=3"> 3 </a>|<a href="index.html?page=4"> 4 </a> </div>
So I thought to output all the href into a list and then extract the element at index 1 like shown below:
tags=soup.find("div", class_="post-footers")
links=tags.get('href')
print links[1]
But it returns the error:
tags.get('href', None)
AttributeError: 'NoneType' object has no attribute 'get'
This means that the tags turned out to be empty. So where in the code did I go wrong?
Thanks, if anyone would be able to help
Update: It is Python: 2.7
It looks like you're new here. If you want to get involved, click one of these buttons!