Web Scraping for a Site that Uses Inline Styles

node , javascript , scraping United States
  • 6 months ago

    The view source for the site that I am trying to scrape looks like this:

    <tr class="productListing-even">
    <td align="center" valign="top" class="productListing-data" style="position:relative;padding-bottom: 5px;" width="25%"><a style="position:relative;float:left;" href="product_info.php?products_id=477998&kind=2&cPath=172_23_45&description=Marquise-Floral-Crystal-Adjustable-Evening-Bracelet-/-Anklet"><img src="images/20200228/thumb/EVB1133-@BK-JET@ADJ-575H@477998@725@04@200.jpg" title="Marquise Floral Crystal Adjustable Evening Bracelet / Anklet" width="200" border="0" height="200" alt="Marquise Floral Crystal Adjustable Evening Bracelet / Anklet"><span class="small_cart" ></span></a>
    

    I am trying to scrape the image links with the following code:

    const rp = require('request-promise');
    const $ = require('cheerio');
    const url = 'https://www.example.com';
    
    rp(url)
      .then(function(html) {
    
    console.log($('tr.productListing-even', html).text());
    console.log($('td.productListing-data > a > img', html).text());
    console.log($('[width="200"]','[border="0"]','[height="200"]', html).text());
    console.log($('a:style*="position:relative"', html).text());
      })
      .catch(function(err) {
        //handle error
      });
    

    I am not getting any output when I run >node test.js.

  • 6 months ago

    My code didn't work because it was requesting the wrong URL. After I changed the URL, it worked.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup