在 DOM 个节点之间创建关系

Create relationship between DOM Nodes

我正在尝试抓取一个 e-commerce 之类的网站,我需要在其中建立列表标题与其描述之间的关系。问题是我不知道如何可靠地这样做,因为有些列表有描述——有些则没有。因此,我无法可靠地使用 for 循环将标题与描述相关联。能否请您提供您的建议?

这就是我的想法,但它并不可靠:

const allTitles= document.querySelectorAll(".title");
const arrayOfTitlesAndDescription= allTitles.map((title,index) => { title :document.querySelectAll(".description")[index] } )

非常感谢!

This image would help you understand better , if the question is unclear

编辑:

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")

搜索包含 .title.description 的某些 div 标签,并针对每个此类标签搜索天气,其子项是否有任何描述。