我正在使用 Apify 从 json 文件链接中获取数据。这是json数据:
<html>
<body>
<pre>
{"exhibitor-single":[{"firstname":"Ines","lastname":"Konwiarz","email":"georg.jansen@020epos.de"}]}
</pre>
</body>
</html>
所以,我在 apify webscraper 任务中使用了以下代码。
async function pageFunction(context) {
const request = context.request;
const $ = context.jQuery;
var data = $('body > pre').html();
var items = JSON.parse(data);
return {
Url: request.url,
Last_Name: items[`exhibitor-single`].lastname,
First_Name: items[`exhibitor-single`].firstname,
Email: items[`exhibitor-single`].email
};
}
该变量data
具有适用于 json 数据的正确 css 选择器。但是,它没有返回任何数据。谁能帮我找出这里出了什么问题?提前致谢。