【问题标题】:Malformed attribute selector Cheerio格式错误的属性选择器 Cheerio
【发布时间】:2019-03-31 19:00:35
【问题描述】:

我正在请求一个网站并成功获取 html 并使用cheerio 加载它。

问题在于它的错误

const res = await axios.get(download_url);
const $ = cheerio.load(res.data);
let result = $('div[class=w-full mt-6 sm:mt-8 lg:mt-0 lg:w-1/3]').html()

所以我认为导致错误的是空格,但我必须用什么替换它们?

谢谢,

【问题讨论】:

    标签: node.js request cheerio


    【解决方案1】:

    您可以引用该值:

    div[class="w-full mt-6 sm:mt-8 lg:mt-0 lg:w-1/3"]
    

    或使用 .风格:

    div.w-full.mt-6.sm:mt-8.lg:mt-0.lg:w-1/3
    

    你也有可能不需要完整的课程:

    div.w-full.mt-6.sm:mt
    

    【讨论】:

      猜你喜欢
      • 2019-08-31
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      相关资源
      最近更新 更多