Created
November 8, 2009 21:02
-
-
Save captproton/229474 to your computer and use it in GitHub Desktop.
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
| require 'rubygems' | |
| require 'httpclient' | |
| require 'pp' | |
| def get_page_source(page_id) | |
| clnt = HTTPClient.new | |
| body = { 'memberDirectoryPageId' => page_id } | |
| uri = "http://www.peninsulashops.com/Content/Members/MemberDirectoryWebService.asmx/LoadMembers" | |
| return clnt.post(uri, body).content | |
| end | |
| def parse_page(page) | |
| records = page.match(/\[\[(\{.+\})\],/)[1] | |
| results = [] | |
| records.scan(/(\{c1:\[(.+?)'\}\]\})/) do |record| | |
| result = [] | |
| record[0].scan(/v:'(.*?)'\}/) do |vals| | |
| result << vals[0] | |
| end | |
| results << result | |
| end | |
| return results | |
| end | |
| map_page_data = get_page_source(463055) # This is a fixed page ID | |
| # | |
| # pp parse_page( map_page_data ) | |
| # puts parse_page( map_page_data ).size | |
| # | |
| # parse_page( map_page_data ).each do |location| | |
| # #m = Model.new | |
| # #m.name = location[0] | |
| # #m.url = location[4] | |
| # #m.save | |
| # end | |
| ## listings_page_data = get_page_source(379519) # This is a fixed page ID | |
| listings_page_data = get_page_source(463055) # This is a fixed page ID | |
| pp parse_page( listings_page_data ) | |
| puts parse_page( listings_page_data ).size | |
| # Same as Above... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment