gpt4 book ai didi

用于获取网页大小(以字节为单位)的 Ruby 代码

转载 作者:数据小太阳 更新时间:2023-10-29 07:56:53 25 4
gpt4 key购买 nike

我想计算网页的大小(以字节为单位),例如 www.google.com 的大小约为 44kb,facebook.com 的大小约为 17k。我已经尝试过 Nokogiri 来计算 HTML 的长度,但它为 Google 提供了 8k,为 Facebook 提供了 32k。我不想使用任何第三方工具,我想在我的应用程序中计算它。

最佳答案

此代码示例应该可以帮助您上手。它下载站点,并使用长度方法检索大小。

require 'net/http'
require 'fileutils' #I'm pretty sure this is needed for the delete method
class HttpSample
def downloadGoogleHome
proxy = Net::HTTP::Proxy('ipaddress', portnumber) # use actual ip and port
url = URI.parse('http://www.google.com')
http_response = proxy.get_response(url)
puts http_response.body.length #size
end
s = HttpSample.new
s.downloadGoogleHome
end

关于用于获取网页大小(以字节为单位)的 Ruby 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com