我正在编写一个 rake 任务,它的功能是从其他网页获取信息。为此,我使用 open-uri 和 nokogiri。我已经在开发中进行了测试并且它可以完成工作,但是随后我部署到生产服务器并失败了。
这是代码:
require 'open-uri'
require 'nokogiri'
desc 'recover eventos llerena'
task recover_eventos_llerena: :environment do
enlaces = []
# Getting index and all links
url = open(URI.parse("https://llerena.org/eventos/lista"))
page = Nokogiri::HTML(url)
page.css("a.fusion-read-more").each do |line|
enlaces.push(line.attr('href'))
end
enlaces = enlaces.uniq
#Inspecting everyone of them
enlaces.each do |link|
url = open(URI.parse(link))
page = Nokogiri::HTML(url)
title = page.css("h1").text
if Evento.find_by_titulo(title) == nil
description = page.css(".tribe-events-single-event-description.tribe-events-content.entry-content.description p").text
date = page.css(".tribe-events-abbr").attr('title')
image = page.css(".size-full").attr('src')
Evento.create!(
titulo: title,
remote_imgevento_url: image,
info: description,
fecha: …Run Code Online (Sandbox Code Playgroud) 来自 Jquery $.get,我试图重写一个获取 json 数据的函数。到目前为止,这就是我所做的:
async function get_highlights(){
const mirespuesta = await fetch("/api/v1/gethighlights/"+network_number)
.then(response => {
if (!response.ok) {
throw new Error("HTTP error " + response.status);
}
return response.json();
})
.then(json => {
console.log(json) // --> here, I get the correct dara
return json;
})
.catch(function () {
this.dataError = true;
})
return mirespuesta
} // but I don't get that data returned
Run Code Online (Sandbox Code Playgroud)
但当我调用函数时我才得到这个:
它具有值,但我无法将它们返回或在我的应用程序的主要范围内使用。
我究竟做错了什么?