Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从该表中获取此数据标记id?_Javascript_Node.js_Puppeteer_Selector - Fatal编程技术网

Javascript 如何从该表中获取此数据标记id?

Javascript 如何从该表中获取此数据标记id?,javascript,node.js,puppeteer,selector,Javascript,Node.js,Puppeteer,Selector,我在编码时遇到了一个问题。 我有一张很大的桌子,有很多行。 我使用以下代码从表中获取数据: let tag1 = document.querySelector('body > div.l-global-width.l-container-primary > div > div.l-container-col2.box-userprofile > section > table > tbody > tr:nth-child(1) > td:nth-c

我在编码时遇到了一个问题。 我有一张很大的桌子,有很多行。 我使用以下代码从表中获取数据:

let tag1 = document.querySelector('body > div.l-global-width.l-container-primary > div > div.l-container-col2.box-userprofile > section > table > tbody > tr:nth-child(1) > td:nth-child(2)').innerText;
问题是,我需要从这个表中获取这个标签的id

<tr data-tag-id="7" role="row">
<td class="ord">1</td>
<td>Komedia</td>
<td class="number">2</td>
<td class="number">10</td>
<td class="number">131</td>
<td class="number" data-sort-value="7.44">7,44</td>
<td class="number" data-sort-value="7.21">7,21</td>
<td class="number" data-sort-value="34434">573h&nbsp;54m</td>
</tr>

1.
小媒体
2.
10
131
7,44
7,21
573h 54m
…你可以猜到,我不知道怎么做。我试过一些方法,但没有一种对我有效,而且我没有足够的经验来提出其他的想法


有人能帮我解决吗?非常感谢您的帮助。

使用属性选择器
[]

const ELS_tagId = document.querySelectorAll("tr[data-tag-id]");
这将为您提供一个包含
数据标记id
元素的所有
的集合。
要循环它们,请执行以下操作:

ELS_tagId.forEach(function(el) {
  console.log(el.dataset.tagId); // among which you'll get also that "7"
});

注意,在JS
标记id
→ <代码>标记ID

ID?什么身份证<代码>7?取决于什么条件?还有,为什么你要使用如此脆弱和复杂的seectors?这不是我的网站,我正在编写一个scraper-tho,是的,我需要得到这个id=7.OK。7.取决于什么条件?这是一场争吵。可能有无数其他行具有其他ID。为什么你只需要那7个?是的,我只是需要从这个表中得到这个id,把它和标签名联系起来,但是我不知道怎么做。它可能很简单,但我真的不知道如何根据我发布的选择器获取它。