Last active
July 26, 2017 15:16
-
-
Save LitvinenkoD89/1d5399f7b1461b6310f2a8f7fc00ee2a to your computer and use it in GitHub Desktop.
JOHNSTON & MURPHY
This file contains hidden or 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
# JOHNSTON & MURPHY {source_name: 'johnstonmurphy', batch_number: 6, request_id: 6000000054, request_name: 'JOHNSTON & MURPHY'} | |
scraper_service.scrape do |browser, scraper, init_vars| | |
easy_seeder = Library.lib('EasySeeder') | |
easy_extractor = Library.lib('EasyExtractor') | |
fetcher_agent = Library.lib('FetcherAgent') | |
easy_seeder.seed(source_name: init_vars[:source_name]) do | |
loop_postal_codes "us", radius: 10 do |zip, lat, long| | |
queue_url "http://www.johnstonmurphy.com/on/demandware.store/Sites-johnston-murphy-us-Site/en_US/Stores-FindStores", { | |
method: :post, | |
body: { | |
dwfrm_storelocator_countryCode: 'US', | |
dwfrm_storelocator_distanceUnit: 'mi', | |
dwfrm_storelocator_postalCode: zip, | |
dwfrm_storelocator_maxdistance: 50 | |
} | |
end | |
end | |
easy_extractor.extract( | |
source_name: init_vars[:source_name], | |
scraper: scraper, | |
batch_number: init_vars[:batch_number], | |
request_id: init_vars[:request_id], | |
request_name: init_vars[:request_name], | |
) do | |
find_pages page_format: :html, page_type: 'search' do |url, parser_page, page| | |
retailstores = page.at('.retailstores') | |
factorystores = page.at('.factorystores') | |
unless retailstores.nil? | |
retailstores.search('.store-information').each do |el| | |
name = el.at('.store-name').children[1].text | |
street1 = el.children.children[3].text.gsub("\r", '').gsub("\n", '').gsub("\t", '').gsub(" ", '') | |
city, state_zip = el.children.children[5].text.gsub("\r", '').gsub("\n", '').gsub("\t", '').gsub(" ", '').split(',') | |
state, zip_code = state_zip.split(',') | |
tmp = el.parent.next.next.text.split('.push(new Array(') | |
lat_lang_container = tmp[1] | |
latitude, longitude = lat_lang_container.split(", ") | |
doc_id = store_doc({ | |
# store_id: id, | |
brand: 'JOHNSTON & MURPHY', | |
type: "JOHNSTON & MURPHY", | |
# property_id: id, | |
name: name, # required | |
address_1: street1, | |
# address_2: street2, | |
city: city, | |
state: state, | |
zipcode: zip_code, | |
country: '', | |
lat: latitude, | |
long: longitude, | |
# map_link: page.at('a.map-it').attr('href'), | |
# address_container_html: page.at('.rio-address-section').to_html, | |
# location_url: location_url, | |
flags: { | |
} | |
}) | |
end | |
end | |
unless factorystores.nil? | |
factorystores.search('.store-information').each do |el| | |
name = el.at('.store-name').children[1].text | |
street1 = el.children.children[3].text.gsub("\r", '').gsub("\n", '').gsub("\t", '').gsub(" ", '') | |
city, state_zip = el.children.children[5].text.gsub("\r", '').gsub("\n", '').gsub("\t", '').gsub(" ", '').split(',') | |
state, zip_code = state_zip.split(',') | |
tmp = el.parent.next.next.text.split('.push(new Array(') | |
lat_lang_container = tmp[1] | |
latitude, longitude = lat_lang_container.split(", ") | |
doc_id = store_doc({ | |
# store_id: id, | |
brand: 'JOHNSTON & MURPHY', | |
type: "JOHNSTON & MURPHY FACTORY", | |
# property_id: id, | |
name: name, # required | |
address_1: street1, | |
# address_2: street2, | |
city: city, | |
state: state, | |
zipcode: zip_code, | |
country: '', | |
# lat: latitude, | |
# long: longitude, | |
# map_link: page.at('a.map-it').attr('href'), | |
# address_container_html: page.at('.rio-address-section').to_html, | |
# location_url: location_url, | |
flags: { | |
} | |
}) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment