Q:

Getting href using Beautiful Soup

I am trying to extract a specific link for this html code
<a class="pageNum taLnk" data-offset="10" data-page-number="1" 
href="www.blahblahblah.com/bb32123">Page 1 </a>
<a class="pageNum taLnk" data-offset="20" data-page-number="2" 
href="www.blahblahblah.com/bb45135">Page 2 </a>

As you can see, the link (href) are disorganized, therefore there are no pattern for me to use which means I need to extract the href manually using BeautifulSoup.
I want to specifically get Page 2's href.
These can the code I have now.
 from bs4 import BeautifulSoup
 import urllib

 url = 'https://www.tripadvisor.com/ShowUserReviews-g293917-d539542-r447460956-Duangtawan_Hotel_Chiang_Mai-Chiang_Mai.html#REVIEWS'
 page = urllib.request.urlopen(url)
 soup = BeautifulSoup(page, 'html.parser')
 for link in soup.find_all('a', attrs = {'class' : 'pageNum taLnk'}):
     print (link)

As you can see, I am stuck at trying to obtain the href information specifically for Page 2. Is there anyway to access with extra bit of information within the tags such as data-page-number = "2" or data-offset = "20".

A:

page_2 = soup.find('a', attrs = {'data-page-number' : '2'})

This will only get you the page 2, if you want to get the next page no matter what the current page is, you should find the next page url:
next_page = soup.find('a', attrs = {'class' = 'nav next rndBtn ui_button primary taLnk'})

Some attributes, like the data-* attributes in HTML 5, have names that
  can’t be used as the names of keyword arguments:
data_soup = BeautifulSoup('<div data-foo="value">foo!</div>')
data_soup.find_all(data-foo="value")
# SyntaxError: keyword can't be an expression

You can use these attributes in searches by putting them into a
  dictionary and passing the dictionary into find_all() as the attrs
  argument:
data_soup.find_all(attrs={"data-foo": "value"})
# [<div data-foo="value">foo!</div>]

