You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Power BI中使用Html.Table识别无CSS选择器的标签?

Fixing Time Column Extraction from Unstructured HTML in Power BI

Hey there, let's tackle this Power BI HTML parsing issue you're facing! It's totally common to hit snags with inconsistent HTML structures when building reports, especially when you're learning on the job—great work troubleshooting as far as you have.

The Core Issues

First, let's break down why your current approaches aren't working:

  • nth-child limitations: This selector depends on fixed row/column positions, which falls apart when table structures vary across reports. No wonder it breaks when you scale to other reports!
  • Incorrect contains syntax: Your attempt td[contains='Time'] uses invalid CSS syntax. The correct pseudo-class for text matching is :contains(), and even then, Power BI's web connector might have limited support for it.

Solution 1: Use a Robust CSS Selector (If Supported)

If Power BI's web connector supports the :contains() pseudo-class, you can target the "Time" label cell and then grab its adjacent sibling cell (which holds the actual time value):

{"Time", "td:contains('Time') + td"}

The + selector targets the immediate next sibling <td> right after the one containing "Time"—this works no matter which row the Time pair lives in.

Solution 2: Switch to XPath (More Reliable for Text Matching)

XPath is often more flexible for unstructured HTML, especially when dealing with text content. Use this XPath expression to precisely locate the time value:

{"Time", "//td[text()='Time']/following-sibling::td[1]"}

Let's break this down:

  • //td[text()='Time']: Finds any <td> element with the exact text "Time"
  • /following-sibling::td[1]: Grabs the first immediate sibling <td> right after that label cell

If the "Time" text might have extra spaces or case variations (like " time " or "TIME"), use a case-insensitive check in XPath:

{"Time", "//td[contains(translate(text(), 'TIME', 'time'), 'time')]/following-sibling::td[1]"}

This converts the cell text to lowercase first, so it matches any case variation of "Time".

Quick Tips for Future Parsing

  • Always prioritize selectors that target content (like text labels) over positional ones (nth-child) when dealing with variable structures
  • Test XPath expressions directly in your browser's dev tools (F12 > Console, use $x("your-xpath-here") to preview matches) before plugging them into Power BI
  • If you're unsure about selector support in Power BI, double-check the official docs for the Web.Contents function and its CSS/XPath capabilities

内容的提问来源于stack exchange,提问作者Kevin Ferrell

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 19:49:06