versioninfo()
Julia Version 1.3.0 Commit 46ce4d7933 (2019-11-26 06:09 UTC) Platform Info: OS: Linux (x86_64-pc-linux-gnu) CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
↓インストール(最初に1回だけ実施)
]add HTTP
using HTTP
HTTP.request("GET", "https://www.google.com/search?q=julialang&oe=UTF-8")
HTTP.Messages.Response: """ HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 Date: Fri, 13 Dec 2019 13:03:58 GMT Expires: -1 Cache-Control: private, max-age=0 P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info." Server: gws X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN Set-Cookie: 1P_JAR=2019-12-13-13; expires=Sun, 12-Jan-2020 13:03:58 GMT; path=/; domain=.google.com Set-Cookie: CGIC=; expires=Wed, 10-Jun-2020 13:03:58 GMT; path=/complete/search; domain=.google.com; HttpOnly Set-Cookie: CGIC=; expires=Wed, 10-Jun-2020 13:03:58 GMT; path=/search; domain=.google.com; HttpOnly Set-Cookie: NID=193=hJBgnbkcfmJ1cGOh6zSa2MsVHJJv6OPklqpVXTuEdpGD1OTkAOC3hf8sRsMMYNYD8W9WMMKMcCcvCkeFMFzaN6_v4qlQKNBnW8x870D-0I-U63hPy227Fc5Pta2-pKCnXAOTzInnioznCmt5HPmukXA__RFMPyzoAP53u09fS20; expires=Sat, 13-Jun-2020 13:03:58 GMT; path=/; domain=.google.com; HttpOnly Alt-Svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000 Accept-Ranges: none Vary: Accept-Encoding Transfer-Encoding: chunked <!doctype html><html lang="ja"><head><meta charset="UTF-8"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>julialang - Google 検索</title><script nonce="g4BIzr9klAm/00g+G3gmAg==">(function(){document.documentElement.addEventListener("submit",function(b){var a;if(a=b.target){var c=a.getAttribute("data-submitfalse");a="1"==c||"q"==c&&!a.elements.q.value?!0:!1}else a=!1;a&&(b.preventDefault(),b.stopPropagation())},!0);}).call(this);(function(){var a=window.performance;window.start=(new Date).getTime();a:{var b=window;if(a){var c=a.timing;if(c){var d=c.navigationStart,e=c.responseStart;if(e>d&&e<=window.start){window.start=e;b.wsrt=e-d;break a}}a.now&&(b.wsrt=Math.floor(a.now()))}}window.google=window.google||{};google.aft=function(f){f.setAttribute("data-iml",+new Date)};}).call(this);(function(){window.jsarwt=function(){return!1};}).call(this);(function(){var c=[],e=0;window.ping=function(b){-1==b.indexOf("&zx")&&(b+="&zx="+(new Date ⋮ 73480-byte body """
function do_search(results::Channel{Tuple{String, Float64, HTTP.Messages.Response}}, engine::String, url::String)
res, exec_time = @timed HTTP.request("GET", url)
if isopen(results)
put!(results, (engine, exec_time, res))
end
end
do_search (generic function with 1 method)
function print_response(engine, exec_time, response)
println("engine: ", engine)
println("exec_time: ", exec_time)
print("response: (")
print("$(response.status) $(HTTP.Messages.STATUS_MESSAGES[response.status]), ")
print("$(length(response.headers)) headers, ")
println("$(length(response.body)) bytes in body)")
end
print_response (generic function with 1 method)
precompile(do_search, (Channel{Tuple{String, Float64, HTTP.Messages.Response}}, String, String))
precompile(print_response, (String, Float64, HTTP.Messages.Response))
true
channel = Channel{Tuple{String, Float64, HTTP.Messages.Response}}(1)
@async do_search(channel, "Google", "https://www.google.com/search?q=julialang&oe=UTF-8")
res0 = take!(channel)
print_response(res0...)
close(channel)
engine: Google exec_time: 0.487161003 response: (200 OK, 16 headers, 73480 bytes in body)
function main()
results = Channel{Tuple{String, Float64, HTTP.Messages.Response}}(3)
searches = [
"Google"=>"https://www.google.com/search?q=julialang&oe=UTF-8",
"Bing"=>"https://www.bing.com/search?q=julialang",
"DuckDuckGo"=>"https://duckduckgo.com/?q=julialang"]
for (engine, url) = searches
@async do_search(results, engine, url)
end
res0 = take!(results)
close(results)
print_response(res0...)
end
main (generic function with 1 method)
precompile(main, ())
true
main()
engine: Google exec_time: 0.435377601 response: (200 OK, 16 headers, 73474 bytes in body)
main()
engine: DuckDuckGo exec_time: 0.25063164 response: (200 OK, 18 headers, 19049 bytes in body)
main()
engine: DuckDuckGo exec_time: 0.287571225 response: (200 OK, 18 headers, 19049 bytes in body)
main()
engine: DuckDuckGo exec_time: 0.287246897 response: (200 OK, 18 headers, 19049 bytes in body)
main()
engine: DuckDuckGo exec_time: 0.289991983 response: (200 OK, 18 headers, 19049 bytes in body)
function main2()
results = Channel{Tuple{String, Float64, HTTP.Messages.Response}}(3)
searches = [
"Google"=>"https://www.google.com/search?q=julialang&oe=UTF-8",
"Bing"=>"https://www.bing.com/search?q=julialang",
"DuckDuckGo"=>"https://duckduckgo.com/?q=julialang"]
for (engine, url) = searches
@async do_search(results, engine, url)
end
res1 = take!(results)
print_response(res1...)
println()
res2 = take!(results)
print_response(res2...)
println()
res3 = take!(results)
print_response(res3...)
close(results)
end
main2 (generic function with 1 method)
precompile(main2, ())
true
main2()
engine: DuckDuckGo exec_time: 0.360540393 response: (200 OK, 18 headers, 19049 bytes in body) engine: Bing exec_time: 0.429006315 response: (200 OK, 16 headers, 158713 bytes in body) engine: Google exec_time: 0.508506785 response: (200 OK, 16 headers, 73474 bytes in body)
main2()
engine: DuckDuckGo exec_time: 0.290471476 response: (200 OK, 18 headers, 19049 bytes in body) engine: Bing exec_time: 0.374741239 response: (200 OK, 16 headers, 157068 bytes in body) engine: Google exec_time: 0.493652595 response: (200 OK, 16 headers, 73480 bytes in body)