1

我正在使用 X-ray JS 包从页面中抓取表格。使用 JSON 字符串中的 CSS 选择器数组指定所需的标签和属性。

"{[ 'th, td' ]}"正确地从 allthtdtags 获取内容。

我还需要其中的img标签,td所以我捕获图标。

什么选择器字符串可以做到这一点?

https://github.com/lapwinglabs/x-ray

4

1 回答 1

2

为了img在 a 中选择标签td,CSS 选择器将是td img.

th, td, td img {
  border: 2px solid black;
}
td img {
  height: 20px;
  width: 20px;
}
<table>
  <tr>
    <th>Heading 1</th>
    <th>Heading 2</th>
  </tr>
  <tr>
    <td>
      <img src='http://lorempixel.com/100/100/nature/1' />
    </td>
    <td>Some description</td>
  </tr>
  <tr>
    <td>
      <img src='http://lorempixel.com/100/100/nature/2' />
    </td>
    <td>Some description</td>
  </tr>
</table>

因此,对于 X 射线,您可能需要将其编写如下:(基于所提到的 th,td)

{[ 'th, td, td img' ]}
于 2016-03-01T07:57:47.493 回答