Web scraping 从ebay上抓取智能手表列表的网站

Web scraping 从ebay上抓取智能手表列表的网站,web-scraping,Web Scraping,从给定链接: 和 列出所有smartwatches及其规格的详细信息,并以表格形式显示。详细信息和特性可以通过以下方式获得: const cheerio=require(“cheerio”); 常量axios=要求(“axios”); const MAIN_URL=”https://www.ebay.com/b/Smart-Watches/178893/bn_152365"; 常量AXIOS_选项={ 标题:{ “用户代理”: “Mozilla/5.0(Macintosh;英特尔Mac OS X

从给定链接:


列出所有smartwatches及其规格的详细信息,并以表格形式显示。

详细信息和特性可以通过以下方式获得:

const cheerio=require(“cheerio”);
常量axios=要求(“axios”);
const MAIN_URL=”https://www.ebay.com/b/Smart-Watches/178893/bn_152365";
常量AXIOS_选项={
标题:{
“用户代理”:
“Mozilla/5.0(Macintosh;英特尔Mac OS X 10_9_3)AppleWebKit/539.75.14(KHTML,类似Gecko)版本/7.0.3 Safari/7046A194A”,
},
};
函数getLinks(searchResultsUrl){
返回axios.get(searchResultsUrl,axios_选项)。然后(函数({data}){
让$=cheerio.load(数据);
常量链接=[];
$(“.s-项目链接”)。每个(功能(i,el){
链接[i]=$(el.prop(“href”);
});
返回链接;
});
}
这将为您提供每个产品的链接。接下来,您需要在解析器中运行每个链接,如下所示:

函数getSpecs(productURL){
返回productUrls.map((url,i)=>{
返回axios.get(url).then(函数({data}){
常量规格=[];
常量标签=[];
让$=cheerio.load(数据);
$(“.attrLabels”)。每个(函数(索引,元素){
常量标签=$(元素)
.text()
.替换(/\s/gi,“”)
.replace(//gi,“”)
.替换(“:”,“”);
常量规范=$(元素)
.next()
.find(“span:not(#readFull)”)
.text()
.替换(/\s/gi,“”)
.替换(//gi,“”);
标签[索引]=标签;
规格[索引]=规格;
});
常数完成={
链接:url,
};
for(设j=0;jPromise.all(承诺))
.然后(日志规格)
.catch((e)=>{
控制台日志(e);
过程。退出(1);
});
你可以看到它是如何工作的

输出:

{
  link: "https://www.ebay.com/itm/233956373339?hash=item3678e2f35b:g:srgAAOSwKUFggjLm&var=533600782928",
  "Condition:":
    "A brand-new, unused, unopened, undamaged item in its original packaging (where packaging is applicable). Packaging should be the same as what is found in a retail store, unless the item is handmade or was packaged by the manufacturer in non-retail packaging, such as an unprinted box or plastic bag. See the seller's listing for full details.See all condition definitions- opens in a new window or tab",
  Brand: "HuaweiHuawei",
  Marke: "Huawei",
  Model: "Band 6",
  Armbandmaterial: "Silikon",
  "Case Size": "22 mm",
  Modell: "Band 6",
  "Compatible Operating System": "Android, iOS - Apple",
  "Kompatibles Betriebssystem": "Android, iOS - Apple",
  "Band Material": "Silicone",
}