1

I am using the X-ray JS package to scrape a table from a page. Desired tags and attributes are specified using an array of CSS selectors in a JSON string.

"{[ 'th, td' ]}" correctly gets content from all th and td tags.

I additionally need the img tags within td so I capture icons.

What selectors string would do that?

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

Harry
  • 87,580
  • 25
  • 202
  • 214
Dizzley
  • 487
  • 6
  • 16

1 Answers1

2

For selecting the img tags within a td, the CSS selector would be 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>

So, for X-ray you'd probably need to write it as follows: (based on what is mentioned in question for th, td)

{[ 'th, td, td img' ]}
Harry
  • 87,580
  • 25
  • 202
  • 214
  • Since `th` is present in the rules, if there can be an `img` inside a `th`, you need to add `th img` – Asons Mar 01 '16 at 08:11
  • @LGSon: True, but question said *select all img within td* so I excluded it :) – Harry Mar 01 '16 at 08:12
  • @LGSon That's OK, you reminded me to check but my `th` tags don't have `img`. I will test this in Xray when I get a chance. – Dizzley Mar 01 '16 at 11:05
  • 1
    @Harry Thanks - looks right to me. Also thanks for formatting my question, I was struggling on my phone. – Dizzley Mar 01 '16 at 11:06
  • 1
    @Harry Just flag these comments as obsolete when you are all done – Asons Mar 01 '16 at 11:10