[英]How do I get whole html from Apify Cheerio crawler?
我想獲得整個 html 而不僅僅是文本。
Apify.main(async () => {
const requestQueue = await Apify.openRequestQueue();
await requestQueue.addRequest({
url: //adress,
uniqueKey: makeid(100)
});
const handlePageFunction = async ({ request, $ }) => {
var content_to = $('.class')
};
// Set up the crawler, passing a single options object as an argument.
const crawler = new Apify.CheerioCrawler({
requestQueue,
handlePageFunction,
});
await crawler.run();
});
當我嘗試這個時,爬蟲返回復雜的 object。 我知道我可以使用.text() 從 content_to 變量中提取文本,但我需要帶有類似標簽的整個 html。 我應該怎么辦?
如果我理解正確 - 你可以只使用.html()
而不是.text()
。 這樣,您將獲得內部 html 而不是元素的內部文本。
另一件要提的事情 - 你也可以把body
放到handlePageFunction
arg object: const handlePageFunction = async ({ request, body, $ }) => {
body
將包含頁面的整個原始 html。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.