title: scraping pagination with Python and Beautiful Soup
body: <p>I am new in Python and also in Web scraping...</p>
  
  <p>I am trying to select all the pages from this webpage</p>
  
  <p><a href="http://www.pour-les-personnes-agees.gouv.fr/annuaire-ehpad-en-hebergement-permanent/64/0" rel="nofollow noreferrer">http://www.pour-les-personnes-agees.gouv.fr/annuaire-ehpad-en-hebergement-permanent/64/0</a></p>
  
  <p>this is quite complicated: I saw the html code with "active first" and "next last.</p>
  
  <p>I did a python code and it worked for 4 pages (page 2,3,4 and 11)</p>
  
  <pre><code>import requests
  from bs4 import BeautifulSoup
  url_pagination= "http://www.pour-les-personnes-agees.gouv.fr/annuaire-ehpad-en-hebergement-permanent/64/0"
  dept_page_Url=[]
  r=requests.get(url_pagination)
  soup = BeautifulSoup(r.content, "html.parser")
  pagination= soup.find_all("ul",{"class":"pagination"})
  if len(pagination) == 0 :
      dept_page_Url.append(url_pagination)
  else:
      for page_url_list in pagination:
          for page_url in page_url_list.find_all("a"):
              dept_page_Url.append(root_url + page_url.get('href'))
  print(dept_page_Url)
  </code></pre>
  
  <p>In fact I know why I have just 4 pages, it is because I selected only the "Href" html code. But I don't know how to improve my code. </p>
  
  <p>Any clue such as a webpage with some information to help me or some who know how to do it???</p>
  
  <p>Thanks a lot </p>