5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/yelp_html_parser/business.rb', line 5
def self.search(sw_latitude, sw_longitude, ne_latitude, ne_longitude, start_index = 0)
link = YelpHtmlParser::YELP_DOMAIN +
"search?start=#{ start_index }&l=g:#{ sw_latitude },#{ sw_longitude },#{ ne_latitude },#{ ne_longitude }"
user_agent = "googlebot"
options = { 'User-Agent' => 'Googlebot', 'read_timeout' => '20' }
doc = Nokogiri::HTML(open(link, options))
content = doc.css(BUSINESS_SEARCH_RESULTS_CSS_PATH)
content.css('.search-result').map do |business_content|
YelpHtmlParser::ResourceParsers::Business.new(business_content).build_business
end
rescue OpenURI::HTTPError => e
fail YelpHtmlParser::Errors::NetworkError
end
|