サーバーからHTMLを取得する代わりに、既にメモリにHTML文字列があり、Seleniumを使用してその内容を確認したいと思います。それは可能ですか?
1 に答える
0
必要に応じて、ローカルhtmlファイルを文字列またはローカルtxtファイルとして操作できます。
Rubyでそれを行う方法は次のとおりです。
require 'open-uri'
require 'nokogiri'
# *** open a URL as a string or as a local txt file
# *** strip the file out of unnecessary html tags and encode chars ***
$url = driver.current_url
$txt_file = open($url)
$raw_contents = $txt_file.read
$html = Nokogiri::HTML(CGI.unescapeHTML($raw_contents)).content
#here we strip the web page fetched out of all hmtl tags and encoded chars
$txt_file = File.new('c:\ruby193\bin\web-content\web_read.txt', "w")
#web_read.txt should now contain a stripped, pure txt file
$txt_file.write($html)
$txt_file.close
于 2013-03-15T11:03:04.003 に答える