I am trying to view the full content of the website fortune.com/best-companies The original code has the following tag in its script :
<nav id="bottom-panel-pagination" class="panel-pagination hasNextOnly">
<div data-event="view left" class="prev-page icon-new-left-arrow"></div>
<div data-event="view right" class="next-page icon-new-right-arrow"></div>
</nav>
I want to change the class attribute "panel-pagination hasNextOnly" to "panel-pagination hasNoPagination" using BeautifulSoup. My python code looks like this :
import urllib2
from bs4 import BeautifulSoup
quote_page = "http://fortune.com/best-companies/"
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, "html.parser")
fullpage = soup.find('nav', attrs = {'class' : 'panel-pagination hasNextOnly'})
print fullpage
I want to change attrs = {'class' : 'panel-pagination hasNextOnly'} to attrs = {'class' : 'panel-pagination hasNoPagination'}
The website should reload after this so that I can further scrap it. How do I do it? Please help.
Beautifulsoup provides facility to change attributes as..
soup.find('nav')['attribute'] = 'new-attribute-values'
fullpage = soup.find('nav', attrs = {'class' : 'panel-pagination hasNextOnly'})
fullpage['class'] = 'panel-pagination hasNoPagination'
print (fullpage)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With