Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import requests
  3.  
  4. req = requests.session()
  5.  
  6.  
  7. def getCandidateList():
  8. candidateURLs = []
  9. url = "http://vote.labour.org.uk/all-candidates"
  10. r = req.get(url).text
  11. soup = BeautifulSoup(r)
  12. candidateList = soup.find("div", {"class": "candidate-results"})
  13. for candidate in candidateList.findAll("li"):
  14. candidateURL = candidate.find("a", href=True)["href"]
  15. if candidateURL[0] == "/": candidateURL = candidateURL[1:]
  16. candidateURLs.append("http://vote.labour.org.uk/" + candidateURL)
  17. return candidateURLs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement