Skip to content

Instantly share code, notes, and snippets.

@fables-tales
Created February 1, 2014 16:09
Show Gist options
  • Save fables-tales/8754282 to your computer and use it in GitHub Desktop.
Save fables-tales/8754282 to your computer and use it in GitHub Desktop.
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