Last active
November 12, 2020 14:41
-
-
Save Mosquid/f8f30eb9a8d03dd138ee2b432a4f4dc6 to your computer and use it in GitHub Desktop.
gearbest parsing descriptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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