我正在使用 X-ray JS 包从页面中抓取表格。使用 JSON 字符串中的 CSS 选择器数组指定所需的标签和属性。
"{[ 'th, td' ]}"
正确地从 allth
和td
tags 获取内容。
我还需要其中的img
标签,td
所以我捕获图标。
什么选择器字符串可以做到这一点?
我正在使用 X-ray JS 包从页面中抓取表格。使用 JSON 字符串中的 CSS 选择器数组指定所需的标签和属性。
"{[ 'th, td' ]}"
正确地从 allth
和td
tags 获取内容。
我还需要其中的img
标签,td
所以我捕获图标。
什么选择器字符串可以做到这一点?
为了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' ]}