如何在CSS选择器中指定“all td和all td img”?

时间:2016-03-01 07:49:08

标签: css css-selectors x-ray

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

"{[ 'th, td' ]}"正确获取所有thtd代码中的内容。

我还需要img中的td代码,因此我会抓取图标。

选择器字符串会做什么?

请参阅https://github.com/lapwinglabs/x-ray

1 个答案:

答案 0 :(得分:2)

要选择img中的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>
&#13;
&#13;
&#13;

因此,对于X光片,您可能需要按如下方式编写:(基于对th,td提出的问题)

{[ 'th, td, td img' ]}
相关问题