Guest User

Untitled

a guest
Nov 22nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. URL_QS = 'https://en.wikipedia.org/wiki/Kazakhstan'
  2. r = requests.get(URL_QS)
  3. soup = BeautifulSoup(r.text, 'lxml')
  4.  
  5. # Only keep the infobox (top right)
  6. infobox = soup.find("table", class_="infobox geography vcard")
  7.  
  8. if infobox:
  9. formation = infobox.find_next(text = re.compile("Formation"))
  10.  
  11. if formation:
  12. independence = formation.find_next(text = re.compile("independence"))
  13.  
  14. if independence:
  15. independ_date = independence.find_next("td").text
  16. else:
  17. independence = formation.find_next(text = re.compile("Independence"))
  18.  
  19. if independence:
  20. independ_date = independence.find_next("td").text
  21.  
  22.  
  23. print(independ_date)
  24.  
  25. Almaty
Add Comment
Please, Sign In to add comment