如何识别没有html.table的CSS选择器的标签?

发布于 2025-01-25 02:18:37 字数 861 浏览 2 评论 0 原文

我正在为报告的工作询问,该报告编写了一些书写的HTML代码,其中只有一些标签具有我可以用于创建列的CSS选择器,但其他标签则没有。 (猜猜是谁写的?)我使用nth-child编写了一些解决方法,并将每个步骤描述为所需的选项卡,但是,如所期望的那样,当对所有其他报告扩展时会引起问题,因为并非每个桌子都与所包含的内容相似。

我的工作代码:

        {"Rule ID", "td[class='rule-id']"}

但是,下一列我使用了以下内容:

        {"Time", "div[class='panel-body'] > TABLE > TBODY > TR:nth-child(6) > TD:nth-child(2)"}

哪些表中确实会抓住时间,但是在其他表中,它抓住了错误的标签。我想知道是否有一种方法可以参考标签之间的信息。时间代码看起来像这样:

<table>
  ...
  <tr>
    <td>Time</td>
    <td>2022-04-28T10:01:15+00:00</td>
  </tr>
  ...
</table>

我尝试过,但是它导致了100%空的列:

 {"Time", "td[contains='Time']"}

这是我的第一个项目,所以我在学习时学习,并通过Google找到了大多数问题的答案,但我无法``这个问题都相当短,以找到一个很好的结果。所有代码都在我的GFE上,因此我无法在这里分享,希望我可以分享的位已经足够了。 预先感谢您的帮助!

I am writing a query for work for a report that has some poorly written HTML code where only some of the tags have a CSS selector I can use for creating my columns but others don't. (Guess who wrote it?) I wrote some workarounds using nth-child and describing each step to the desired tab but, as expected, when scaled up to all the other reports it causes issues because not every table is alike with what it contains.

My working code:

        {"Rule ID", "td[class='rule-id']"}

However the next column I used this:

        {"Time", "div[class='panel-body'] > TABLE > TBODY > TR:nth-child(6) > TD:nth-child(2)"}

Which in some of the tables does grab the time, but in others it grabs the wrong tag. I'm wondering if there's a way I can refer to the information in-between the tags. The time code looks like this:

<table>
  ...
  <tr>
    <td>Time</td>
    <td>2022-04-28T10:01:15+00:00</td>
  </tr>
  ...
</table>

I tried this but it results in a 100% empty column:

 {"Time", "td[contains='Time']"}

This is my first project in Power BI so I'm learning as I go and have found answers to most of my questions through Google but I couldn't quite phrase this question properly to find a good result. All of the code is on my GFE so I can't get it over here to share, hopefully the bits I could share are enough.
Thank you in advance for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋顶上的小猫咪 2025-02-01 02:18:37

如果您链接该网站,我可以给出更好的答案。


有一个可选的第三参数,可让您更多地访问属性。

{“ name”,“ selector”} 将成为 {“ name”,“ selector”,每个_} ,ex:

= Html.Table(Source,
        {
            {"Name", "Selector", each _ }
        }
    )

selector

:selector

td [包含='time']

这不是在寻找您的HTML,它将与此匹配。这是一个很好的参考/作弊表

  • ” ://developer.mozilla.org/en-us/docs/web/css/attribute_selectors
<td contains='Time'>

在Web控制台中的浏览器中测试选择器

,您可以使用CSS选择器查询来预览将选择的CSS选择器查询。

Firefox使用函数 $ $$ 具有速记。否则使用 document.queryselector() document.queryselectorall()

您的 rowselector

如果要使用 $$(”表。 ;

table& gt img src =“ https://i.sstatic.net/2vwzs.png” alt =“ Horizo​​ntal-preview”>

您的 colugn> colugnnameselectorpairs

,然后 table.table.table.table&gt; *&gt; tr&gt; :nth-​​child(1)

”

来自:

If you link the site I can give a better answer.


There's an optional 3rd parameter, that gives you more access to attributes.

{"Name", "Selector"} would become {"Name", "Selector", each _ }, ex:

= Html.Table(Source,
        {
            {"Name", "Selector", each _ }
        }
    )

selector

td[contains='Time']

This isn't looking for what your html, it would match this. Here's a good reference/cheatsheet

<td contains='Time'>

Testing Selectors in a browser

In the web console, you can use a CSS Selector query to preview what it will select.

Firefox has shorthand using the function $ and $$ . otherwise use document.querySelector() and document.querySelectorAll()

Your RowSelector

If you were to use $$("TABLE.table > * > TR") as your RowSelector

horizontal-preview

Your columnNameSelectorPairs

And then TABLE.table > * > TR > :nth-child(1)

vertical-preview

From:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文