gpt4 book ai didi

http-status-code-404 - Mechanize/Ruby读取404页面源代码

转载 作者:行者123 更新时间:2023-12-04 00:14:57 25 4
gpt4 key购买 nike

我所做的只是加载 Mechanize ,并获得一个返回 404 的页面。但这正是我想要的。 404 页面有很多我想在我的例子中使用的 html。

a = mechanize.new
a.get('http://www.youtube.com/watch?v=e4g8jriw4rg')
a.page
=> nil

我似乎找不到关于此的任何进一步信息。

最佳答案

您需要处理异常:

begin
page = a.get 'http://www.youtube.com/watch?v=e4g8jriw4rg'
rescue Mechanize::ResponseCodeError => e
puts e.response_code # the status code as a string, e.g. "404"
page = e.page
end

puts page.title

关于http-status-code-404 - Mechanize/Ruby读取404页面源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13188195/

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