From 1913efad43a69505dc08236f4720b5423f61ee13 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Mon, 10 Oct 2022 09:59:14 +0800 Subject: [PATCH] update test scripts --- demo/lang/ruby/2_webpage_extract.rb | 17 ++++++++--------- demo/lang/ruby/3_http_interface_call.rb | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/demo/lang/ruby/2_webpage_extract.rb b/demo/lang/ruby/2_webpage_extract.rb index 5dba7442..0d30287a 100755 --- a/demo/lang/ruby/2_webpage_extract.rb +++ b/demo/lang/ruby/2_webpage_extract.rb @@ -8,17 +8,16 @@ pid=0 1. Load web page from url http://xxx 2. Retrieve img element zt-logo.png in html -3. Check img exist >> `.*zt-logo.png` +3. Check img exist >> `必应` =end -require "open-uri" +require 'uri' +require 'net/http' -uri = 'http://max.demo.zentao.net/user-login-Lw==.html' -html = nil -open(uri) do |http| - html = http.read -end +uri = URI('https://cn.bing.com') +res = Net::HTTP.get_response(uri) +html = res.body -elem = html.match(//).captures -puts ""+elem[0] +elem = html.match(/(.*?)</).captures +puts ""+elem[0] \ No newline at end of file diff --git a/demo/lang/ruby/3_http_interface_call.rb b/demo/lang/ruby/3_http_interface_call.rb index 630fb7c9..d73be22d 100755 --- a/demo/lang/ruby/3_http_interface_call.rb +++ b/demo/lang/ruby/3_http_interface_call.rb @@ -7,18 +7,18 @@ pid=0 1. Send a request to interface http://xxx 2. Retrieve sessionID field from response json -3. Check its format >> `^[a-z0-9]{26}` +3. Check its format >> `^[0-9]{8}` =end -require "open-uri" -require "json" +require 'uri' +require 'net/http' +require 'json' -uri = 'http://max.demo.zentao.net/pms/?mode=getconfig' -html = nil -open(uri) do |http| - html = http.read -end +uri = URI('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1') +res = Net::HTTP.get_response(uri) + +json = JSON.parse(res.body) + +puts json['images'][0]['startdate'] -json = JSON.parse(html) # need json library (gem install json) -puts json['sessionID'] -- GitLab