Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- import requests
- req = requests.session()
- def getCandidateList():
- candidateURLs = []
- url = "http://vote.labour.org.uk/all-candidates"
- r = req.get(url).text
- soup = BeautifulSoup(r)
- candidateList = soup.find("div", {"class": "candidate-results"})
- for candidate in candidateList.findAll("li"):
- candidateURL = candidate.find("a", href=True)["href"]
- if candidateURL[0] == "/": candidateURL = candidateURL[1:]
- candidateURLs.append("http://vote.labour.org.uk/" + candidateURL)
- return candidateURLs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement