mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
updating example scripts
This commit is contained in:
parent
e178bc9f20
commit
9a64fadb56
@ -19,21 +19,18 @@ Signal.trap("INFO") { print_status } unless ENV.key?("CI")
|
||||
|
||||
Thread.start do
|
||||
frontpage = HTTPX.get("https://news.ycombinator.com").to_s
|
||||
|
||||
|
||||
html = Oga.parse_html(frontpage)
|
||||
|
||||
links = html.css('.itemlist a.storylink').map{|link| link.get('href') }
|
||||
|
||||
|
||||
links = html.css('.athing .title a').map{|link| link.get('href') }.select { |link| URI(link).absolute? }
|
||||
|
||||
links = links.select {|l| l.start_with?("https") }
|
||||
|
||||
|
||||
puts links
|
||||
|
||||
|
||||
responses = HTTPX.get(*links)
|
||||
|
||||
|
||||
links.each_with_index do |l, i|
|
||||
puts "#{responses[i].status}: #{l}"
|
||||
end
|
||||
end.join
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
require "httpx"
|
||||
require "oga"
|
||||
|
||||
http = HTTPX.plugin(:persistent).with(timeout: { operation_timeut: 5, connect_timeout: 5})
|
||||
http = HTTPX.plugin(:persistent).with(timeout: { request_timeout: 5 })
|
||||
|
||||
PAGES = (ARGV.first || 10).to_i
|
||||
pages = PAGES.times.map do |page|
|
||||
@ -16,10 +16,11 @@ Array(http.get(*pages)).each_with_index.map do |response, i|
|
||||
end
|
||||
html = Oga.parse_html(response.to_s)
|
||||
# binding.irb
|
||||
page_links = html.css('.itemlist a.titlelink').map{|link| link.get('href') }
|
||||
page_links = html.css('.athing .title a').map{|link| link.get('href') }.select { |link| URI(link).absolute? }
|
||||
puts "page(#{i+1}): #{page_links.size}"
|
||||
if page_links.size == 0
|
||||
puts "error(#{response.status}) on page #{i+1}"
|
||||
next
|
||||
end
|
||||
# page_links.each do |link|
|
||||
# puts "link: #{link}"
|
||||
@ -31,6 +32,11 @@ end
|
||||
links = links.each_with_index do |pages, i|
|
||||
puts "Page: #{i+1}\t Links: #{pages.size}"
|
||||
pages.each do |page|
|
||||
puts "URL: #{page.uri} (#{page.status})"
|
||||
case page
|
||||
in status:
|
||||
puts "URL: #{page.uri} (#{status})"
|
||||
in error:
|
||||
puts "URL: #{page.uri} (#{error.message})"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -6,11 +6,9 @@ include HTTPX
|
||||
URLS = %w[http://nghttp2.org https://nghttp2.org/blog/]# * 3
|
||||
|
||||
client = HTTPX.plugin(:proxy)
|
||||
client = client.with_proxy(uri: "http://61.7.174.110:54132")
|
||||
responses = client.get(URLS)
|
||||
client = client.with_proxy(uri: "http://134.209.29.120:8080")
|
||||
responses = client.get(*URLS)
|
||||
puts responses.map(&:status)
|
||||
|
||||
# response = client.get(URLS.first)
|
||||
# puts response.status
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user