Fix for infinite loop in wpstools #653
This commit is contained in:
@@ -66,25 +66,34 @@ class GenerateList
|
|||||||
def get_popular_items(pages)
|
def get_popular_items(pages)
|
||||||
found_items = []
|
found_items = []
|
||||||
page_count = 1
|
page_count = 1
|
||||||
|
retries = 0
|
||||||
|
|
||||||
(1...(pages.to_i + 1)).each do |page|
|
(1...(pages.to_i + 1)).each do |page|
|
||||||
# First page has another URL
|
# First page has another URL
|
||||||
url = (page == 1) ? @popular_url : @popular_url + 'page/' + page.to_s + '/'
|
url = (page == 1) ? @popular_url : @popular_url + 'page/' + page.to_s + '/'
|
||||||
puts "[+] Parsing page #{page_count}" if @verbose
|
puts "[+] Parsing page #{page_count}" if @verbose
|
||||||
code = 0
|
code = 0
|
||||||
while code != 200
|
|
||||||
|
while code != 200 && retries <= 3
|
||||||
puts red("[!] Retrying request for page #{page} (Code: #{code})") unless code == 0
|
puts red("[!] Retrying request for page #{page} (Code: #{code})") unless code == 0
|
||||||
|
|
||||||
request = @browser.forge_request(url)
|
request = @browser.forge_request(url)
|
||||||
response = request.run
|
response = request.run
|
||||||
code = response.code
|
code = response.code
|
||||||
|
|
||||||
sleep(5) unless code == 200
|
sleep(5) unless code == 200
|
||||||
|
retries += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
page_count += 1
|
page_count += 1
|
||||||
found = 0
|
found = 0
|
||||||
|
|
||||||
response.body.scan(@popular_regex).each do |item|
|
response.body.scan(@popular_regex).each do |item|
|
||||||
found_items << item[0]
|
found_items << item[0]
|
||||||
found = found + 1
|
found = found + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
retries = 0
|
||||||
puts "[+] Found #{found} items on page #{page}" if @verbose
|
puts "[+] Found #{found} items on page #{page}" if @verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -96,6 +105,7 @@ class GenerateList
|
|||||||
def save(items)
|
def save(items)
|
||||||
items.sort!
|
items.sort!
|
||||||
items.uniq!
|
items.uniq!
|
||||||
|
|
||||||
puts "[*] We have parsed #{items.length} #{@type}s"
|
puts "[*] We have parsed #{items.length} #{@type}s"
|
||||||
File.open(@file_name, 'w') { |f| f.puts(items) }
|
File.open(@file_name, 'w') { |f| f.puts(items) }
|
||||||
puts "New #@file_name file created"
|
puts "New #@file_name file created"
|
||||||
|
|||||||
Reference in New Issue
Block a user