Created
February 1, 2014 16:09
-
-
Save fables-tales/8754282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
class YelpRequester: | |
def find_best_thing(self, category, place): | |
root_url = "http://www.yelp.co.uk/search?find_desc=" + category + "&find_loc=" + place + "&ns=1&#sortby=rating" | |
response = requests.get(root_url).text | |
soup = BeautifulSoup(response) | |
best_place = soup.findAll(attrs={"class":"biz-name"})[1] | |
next_url = "http://www.yelp.co.uk/" + best_place.attrs["href"] | |
response = requests.get(next_url).text | |
soup = BeautifulSoup(response) | |
url = "http://" + list(soup.findAll(attrs={"id":"bizUrl"})[0].children)[1].text | |
return {"name": best_place.text, "url": url} | |
if __name__ == "__main__": | |
y = YelpRequester() | |
print y.find_best_thing("hotels", "New York NY") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment