Skip to content

Instantly share code, notes, and snippets.

@Mosquid
Last active November 12, 2020 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mosquid/f8f30eb9a8d03dd138ee2b432a4f4dc6 to your computer and use it in GitHub Desktop.
Save Mosquid/f8f30eb9a8d03dd138ee2b432a4f4dc6 to your computer and use it in GitHub Desktop.
gearbest parsing descriptions
...
parseSpecsTable: (specsTable) => {
let textTable = ""
specsTable.forEach((row) => {
const [keyNode, valueNode] = row.children
const key = keyNode.textContent.trim()
const value = valueNode.textContent.trim()
textTable += `<strong>${key}</strong>: <p>${value}</p>`
})
return textTable
},
getProductDescription: function () {
const textDescNode =
document.querySelector(".textDescContent") ||
document.querySelector(".desc_simp")
let specsTable = document.querySelectorAll(".sizeDescTable")
if (!specsTable.length)
specsTable = document.querySelectorAll(".product_pz_info table tr")
const textDesc = textDescNode.innerHTML
if (!specsTable) return textDesc
const textTable = this.parseSpecsTable(specsTable)
return textDesc.concat(textTable)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment