Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在API中打开数组(木偶演员)_Javascript_Arrays - Fatal编程技术网

Javascript 在API中打开数组(木偶演员)

Javascript 在API中打开数组(木偶演员),javascript,arrays,Javascript,Arrays,我正在尝试从API打开一个数组 尝试使用代码 const names_2=wait page.evaluate(()=>Array.from(document.querySelectorAll('.mainDiv>defaction'),defaction=>defaction.innerText)) 但是没有运气 这是我的意见 const puppeteer = require('puppeteer'); (async () => { const browser = await p

我正在尝试从API打开一个数组

尝试使用代码 const names_2=wait page.evaluate(()=>Array.from(document.querySelectorAll('.mainDiv>defaction'),defaction=>defaction.innerText))

但是没有运气

这是我的意见

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.goto('http://xmlopen.rejseplanen.dk/bin/rest.exe/multiDepartureBoard?id1=8600646&format=json')

    const result = await page.evaluate(() => {
      let temperature = document.getElementsByTagName("pre")[0].innerText;
temperature = JSON.parse(temperature);
    return {
        temperature
      }
  })

  console.log(result)


})()
这是我的输出

{
  temperature: {
    MultiDepartureBoard: {
      noNamespaceSchemaLocation: 'http://xmlopen.rejseplanen.dk/xml/rest/hafasRestMultiDepartureBoard.xsd',
      Departure: [Array]
    }
  }
}

你在这里做的事毫无意义。只需请求数据即可

const rp = require('request-promise');
rp.get({
    uri: 'http://xmlopen.rejseplanen.dk/bin/rest.exe/multiDepartureBoard?id1=8600646&format=json',
    json: true
})
    .then(res => res.MultiDepartureBoard.Departure)
    .map(e => console.log(e))
;

为什么要访问返回JSON字符串的页面?你就不能直接得到它并解析它吗?我不知道怎么做,但我会调查的。刚刚尝试从url中删除“&format=json”,但没有成功。这正是我想要它做的!