该API提供了网站的缩略图。
<img style="-webkit-user-select: none" src="http://webthumb.bluga.net/easythumb.php?user=00000&url=www.consumerreports.com&hash=sdf9g879d8f7g9sd8fg7s9df&size=medium&cache=30">
用户ID和哈希值已删除,但如果正确,此标记将在您的页面上产生一个名为的小缩略图easythumb.jpeg
。
有什么办法可以抓取该缩略图并将其存储在数据库或AWS中?
还是为防止这种行为而精心设计的webthumb?
编辑:
根据下面的建议尝试了Nokogiri,这是回报。似乎无法从中获取jpg。我对吗?
重要的是要了解什么事情会做什么。这是一些代码,已经过测试,可以下载图像:
require 'nokogiri'
require 'open-uri'
html = '<img style="-webkit-user-select: none" src="http://webthumb.bluga.net/easythumb.php?user=00000&url=www.consumerreports.com&hash=sdf9g879d8f7g9sd8fg7s9df&size=medium&cache=30">'
doc = Nokogiri::HTML(html)
uri = URI.parse(doc.at('img')['src'])
# => #<URI::HTTP:0x007f8e13258520 URL:http://webthumb.bluga.net/easythumb.php?user=00000&url=www.consumerreports.com&hash=sdf9g879d8f7g9sd8fg7s9df&size=medium&cache=30>
File.basename(uri.path)
# => "easythumb.php"
File.open(File.basename("#{ uri.path }.jpeg"), 'wb') { |fo| fo.write(open(uri).read) }
也就是说,该网址无效。打开浏览器页面并粘贴到该URL中将返回“错误哈希”,而不是图像。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句