I am trying to scrape an e-commerce like site, where I need to establish a relationship between the Title of a listing and its description. The problem is that I do not know how to reliably do so, because some listings have a description - some don't. As a result I cannot reliably use a for loop in associating a title with a description. Could you please offer your suggestions ?
This is how I was thinking , but it doesnt work reliably:
const allTitles= document.querySelectorAll(".title");
const arrayOfTitlesAndDescription= allTitles.map((title,index) => { title :document.querySelectAll(".description")[index] } )
Thank you very much !
This image would help you understand better , if the question is unclear
EDIT:
const allCards= document.querySelectorAll(".card");
/// also tried with allCards directly
Array.from(allCards).forEach(card => card.querySelector(".description"));
/// This works, but I don't know how to tell which .card is which
document.querySelectorAll(".card").querySelector(".description")
CodePudding user response:
Search for some div tag that encloses both .title and .description and for each of such tag search weather its children have any description or not.
