获得徽章 10
day32
用cheerio爬百度新闻
const url = "
news.baidu.com";
try {
const response = await axios.get(url);
const $ = cheerio.load(response.data);
// 根据页面结构选择合适的选择器,这里只是一个例子,实际情况可能不同
const articles = $("#pane-news > ul");
const articleData = [];
articles.each((index, element) => {
const title = $(element).find("li.bold-item > a").text().trim();
const link = $(element).find("li.bold-item > a").attr("href");
articleData.push({ title, link });
});
return articleData;
} catch (error) {
console.error(error);
return [];
}
用cheerio爬百度新闻
const url = "
try {
const response = await axios.get(url);
const $ = cheerio.load(response.data);
// 根据页面结构选择合适的选择器,这里只是一个例子,实际情况可能不同
const articles = $("#pane-news > ul");
const articleData = [];
articles.each((index, element) => {
const title = $(element).find("li.bold-item > a").text().trim();
const link = $(element).find("li.bold-item > a").attr("href");
articleData.push({ title, link });
});
return articleData;
} catch (error) {
console.error(error);
return [];
}
展开
评论
点赞
day24
typeof 数据类型
● 基本数据类型 String,Number,Boolean,Null,Undefined
● 引用数据类型 Funcation,Array,Object
typeof undefined // "undefined"
typeof null // "object"
typeof 1 // "number"
typeof "1" // "string"
typeof Symbol() // "symbol"
typeof function() {} // "function"
typeof {} // "object"
typeof new Number(1) // "object"
typeof new String(1) // "object"
typeof 作用于未定义的变量,会报错吗? 答案:不会报错,返回"undefined"。
typeof new Number(1)的返回值是什么?答案:"object"。
Array(1, 2, 3) 等价于 new Array(1, 2, 3)
typeof 数据类型
● 基本数据类型 String,Number,Boolean,Null,Undefined
● 引用数据类型 Funcation,Array,Object
typeof undefined // "undefined"
typeof null // "object"
typeof 1 // "number"
typeof "1" // "string"
typeof Symbol() // "symbol"
typeof function() {} // "function"
typeof {} // "object"
typeof new Number(1) // "object"
typeof new String(1) // "object"
typeof 作用于未定义的变量,会报错吗? 答案:不会报错,返回"undefined"。
typeof new Number(1)的返回值是什么?答案:"object"。
Array(1, 2, 3) 等价于 new Array(1, 2, 3)
展开
评论
点赞