簡體   English   中英

為什么我總是得到 Null?

[英]Why do I keep getting Null?

const request = require('request');
const cheerio = require('cheerio');

request('https://www.ratemyprofessors.com/ShowRatings.jsp?tid=1985428', (error, response, html) => {
    if(!error && response.statusCode ==200){
        //console.log(html);
        const $ = cheerio.load(html); 
        
        const profTopComment = $('.Comments__StyledComments-dzzyvm-0 dvnRbr');
        
        console.log(profTopComment.html());
    }
});

我正在嘗試創建一個 chrome 擴展來從 RatemyProffessor 中抓取數據,但是當試圖從上面的 url 中抓取最有意義的評論時,我一直為空,任何幫助都會很棒!

當我說“獲取空值”時,我的意思是 console.log(profTopComment.html()) 在終端中給我空值。

我正在嘗試抓取最有用的評級。

  • '.Comments__StyledComments-dzzyvm-0.dvnRbr'第二個"." 需要查找具有two不同類的<div></div>元素
  • 基本上只需將代碼中的'.Comments__StyledComments-dzzyvm-0 dvnRbr'更改為'.Comments__StyledComments-dzzyvm-0 dvnRbr' '.Comments__StyledComments-dzzyvm-0.dvnRbr'

例子:

const axios = require('axios');
const cheerio = require('cheerio');

async function testFunc() {
  const result = await 
  axios.get('https://www.ratemyprofessors.com/ShowRatings.jsp?tid=1985428');
  const $ = cheerio.load(result.data);
  const profTopComment = $('.Comments__StyledComments-dzzyvm-0.dvnRbr');
  console.log(profTopComment.html());
}
testFunc();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM