【问题标题】:Why I get wrong link from attribute href from site steam?为什么我从站点 Steam 的属性 href 中得到错误的链接?
【发布时间】:2020-09-29 18:23:28
【问题描述】:

我使用 nodejs 从站点 steam 获取所有链接。

在站点链接中(例如):

  1. https://steamcommunity.com/market/listings/730/Horizon%20Case
  2. https://steamcommunity.com/market/listings/730/Chroma%203%20Case

我明白了:

  1. https://steamcommunity.com/market/listings/730/Horizon%20Case(好)
  2. https://steamcommunity.com/market/listings/730/Chroma%20Case(错误)

我的代码:

var link_part1 = 'https://steamcommunity.com/market/search?category_730_ItemSet%5B%5D=any&category_730_ProPlayer%5B%5D=any&category_730_StickerCapsule%5B%5D=any&category_730_TournamentTeam%5B%5D=any&category_730_Weapon%5B%5D=any&category_730_Type%5B%5D=tag_CSGO_Type_WeaponCase&appid=730&q=case#p1'
var link_part2 = '_price_asc'
var number_page = 1

request(link_part1+number_page+link_part2, function(err, resp, html) {
        if (!err){
          const $ = cheerio.load(html);
          for (i=0; i<10; i++) {
            let box = $("a.market_listing_row_link").eq(i).attr('href')
            console.log(box);
          }
        } else {
          console.log("Error");
        }
});

我做错了什么???

【问题讨论】:

    标签: node.js request href cheerio steam


    【解决方案1】:

    发生这种情况是因为最初此信息不在页面代码中。它是在进程中加载​​的。如果您使用 puppeteer 库,则可以轻松提取此信息。

    【讨论】:

      猜你喜欢
      • 2019-04-17
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 2021-04-07
      相关资源
      最近更新 更多