Class: CrowdFundingParser::Parser::An9
- Defined in:
- lib/crowd_funding_parser/parser/an9.rb
Instance Method Summary collapse
- #get_main_categories(add_categories) ⇒ Object
- #get_project_links(required_status = "online") ⇒ Object
-
#initialize ⇒ An9
constructor
A new instance of An9.
Methods inherited from General
#get_doc_through_url, #get_id, #get_json_through_url, #get_project, #get_result, #parse_content_data, #parse_tracking_data
Constructor Details
#initialize ⇒ An9
Returns a new instance of An9.
8 9 10 11 |
# File 'lib/crowd_funding_parser/parser/an9.rb', line 8 def initialize @url = "http://www.an9.com.tw/Dream/" @status_css_class = ".sideCon>a" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CrowdFundingParser::Parser::General
Instance Method Details
#get_main_categories(add_categories) ⇒ Object
13 14 15 |
# File 'lib/crowd_funding_parser/parser/an9.rb', line 13 def get_main_categories(add_categories) add_categories.select { |c| c[:parent_id].nil? } end |
#get_project_links(required_status = "online") ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/crowd_funding_parser/parser/an9.rb', line 17 def get_project_links(required_status = "online") links = [] error_count = 0 not_found_count = 0 Parallel.each(1..100000, in_precesses: 2, in_threads: 5, progress: "Get #{self} links") do |i| begin link = @url + i.to_s project = get_doc_through_url(link) = project.css(".actMsg p") if .present? && get_string().match(/不存在/) not_found_count += 1 else status = get_status(get_string(project.css(@status_css_class))) if status == required_status links << link end not_found_count = 0 error_count = 0 end rescue Exception => e error_count += 1 raise Parallel::Break if not_found_count >= 50 || error_count >= 50 end end links end |