我想下载一个网址列表,并将它们存储在数据库(Mysql)中。我该如何制作安全的htmls?我可以用什么代替
safe_html = make_safe_it(html) # HERE
在下面的代码中?
require 'mysql2'
require 'open-uri'
HOST = "..."
USER = "..."
PASS = "..."
@client = Mysql2::Client.new(:host=> HOST,:username=>USER,:password => PASS)
@client.query "USE db_test"
@client.query("SELECT id,url from pages").each{ |row|
html = open(row["url"]).read
safe_html = make_safe_it(html) # HERE
@client.query("UPDATE pages SET html = #{safe_html} where id = #{row["id"]} ")
}
答案 0 :(得分:0)
根据https://github.com/brianmario/mysql2使用escaped = client.escape("gi'thu\"bbe\0r's")