【发布时间】:2021-04-10 15:52:29
【问题描述】:
如果这是基本问题,我深表歉意,但我似乎无法说出我的问题以在其他地方找到结果。
基本上,我想知道如何使用 Javascript 从网页中抓取 CSS 属性的实际名称。直观地说,我想使用document.querySelectorAll('a [title]'),但这只是一个选择器,用于获取用这些选择器标记的文本内容,不会刮掉实际标题属性的名称本身。
在下面的示例中,document.querySelectorAll('a [title]') 将选择“A Light in the...”正文,而不是“A Light in the Attic”元标题名称。
<h3>
<a href="catalogue/a-light-in-the-attic_1000/index.html" title="A Light in the Attic">A Light in the...</a>
</h3>
您可以看到为什么这很重要,因为我正在处理的网页在正文中会截断名称,但将其完全写在标题元标记中。
谢谢!
【问题讨论】:
-
你只是想获取title属性的内容吗?
-
是的,谢谢!
标签: css web-scraping css-selectors