Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
How to scrape HTML definition list with x-ray

I am using the x-ray module to scrape data like the following HTML code. How to scrape a definition list like this with x-ray?

<div class="content">
    <h1>Title</h1>
    <div class="productDetails">
        <dl>
            <dt>1</dt>
            <dd>A</dd>
            <dt>2</dt>
            <dd>B</dd>
            <dt>3</dt>
            <dd>C</dd>
        </dl>
    </div>
</div>

I'd like to get the following result:

[
  {
    "productTitle": "Title",
    "productDetails": [
      {
        "attrName": "1",
        "attrDesc": "A"
      },
      {
        "attrName": "2",
        "attrDesc": "B"
      },
      {
        "attrName": "3",
        "attrDesc": "C"
      }
    ]
  }
]

Here is the code I used to scrape the content:

    x(url, '.content', [
    {
      productTitle: 'h1',
      productDetails1: x('div.productDetails', [{attrName: ['dl dt'], attrDesc: ['dl dd | remove_whitespace']}]),
      productDetails2: x('div.productDetails dl', ['dt', 'dd']),
    }
  ])

But I get this result:

[
  {
    "productTitle": "Title",
    "productDetails_1": [
      {
        "attrName": [
          "1",
          "2",
          "3"
        ],
        "attrDesc": [
          "A",
          "B",
          "C"
        ]
      }
    ],
    "productDetails_2": [
      "1",
      "2",
      "3"
    ]
  }
]

How to get the data in the structure I described above?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!