Skip to content

Instantly share code, notes, and snippets.

@msjahun
Created January 28, 2025 13:16
Show Gist options
  • Select an option

  • Save msjahun/3f3d4026d9d8d285e3ef305c9d5d34c9 to your computer and use it in GitHub Desktop.

Select an option

Save msjahun/3f3d4026d9d8d285e3ef305c9d5d34c9 to your computer and use it in GitHub Desktop.
Javascript dom code to extract some site contents: http://www.fortune-machinery.com/single-head-embroidery-machine/
//productPhotosUrls:string[],
const cProductPhotosUrl = [];
document.querySelectorAll("body > div.list_box > div.list_right_ > div.product_4 > div.product_view4 > div.spec-scroll > div > ul > li").forEach(c=>{
const imgTag = c.querySelector("span > img");
cProductPhotosUrl.push({smallImage: imgTag.src, largeImage: imgTag.getAttribute("bimg")});
});
//productName:string,
const cProductName = document.querySelector("body > div.list_box > div.list_right_ > div.product_4 > div.right4_text > h1").innerText;
const dProductUrl = window.location.href;
const recommendedProducts = [];
document.querySelectorAll("body > div.list_box > div.list_right_ > div.product_4 > div.container.product_details > div > div > ul > li").forEach(c=>{
const cImage = c.querySelector("img").src;
const cProductName = c.querySelector("p > a").innerText;
const cProductUrl = c.querySelector("p > a").href;
recommendedProducts.push({image: cImage, productName: cProductName, productUrl: cProductUrl});
});
//ProductDescription:string,
const parentElement = document.querySelector("body > div.list_box > div.list_right_ > div.product_4 > div.container.product_details > div > div:nth-child(2)")
const childElement = parentElement.querySelector('.rollPro1');
if (childElement) {
childElement.remove();
} else {
// console.log('Element with class "r2" not found.');
}
const parentText = parentElement.innerText;
const itemz = document.querySelectorAll("body > div.list_box > div.list_right_ > div.location > a");
const cCategory = itemz[itemz.length-1].innerText;
const finalProduct ={
productPhotosUrls: cProductPhotosUrl,
productName: cProductName,
productCategory: cCategory,
ProductDescription: parentText,
productUrl:dProductUrl,
recommendedProducts:recommendedProducts
}
finalProduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment