WordPress.org

Ready to get started?Download WordPress

Forums

Get DD element value from other website? (3 posts)

  1. tomsko
    Member
    Posted 1 year ago #

    I am looking for the best and server friendly method of geting DD element value echo'ed on my WordPress site, inside div.

    I need to scrap 9.th <dd>value</dd> from other website, and I've had no success. This is the jQuery code I found online, but it doesn't work.

    $(document).ready(function() {
      $.get("http://otherwebsite.com", function(data) {
        var resp = $(data);
        $("dd:eq(9)", resp).appendTo("body"); // dd:eq(9) for selecting 9.th DD value
      });
    
      setTimeout(function() {
        location.reload(true);
      }, 10000);
    });
  2. You're probably better off retrieving the body using the HTTP API then scraping the result. I guess it largely depends on whether you need the data client-side (as with js) and whether you need to prepare it for display on the other side (easier server-side).

  3. tomsko
    Member
    Posted 1 year ago #

    I already wrote PHP code, as it turns out Javascript can'y do that. At all :)
    Just in case anyone is looking -

    <?php
    $data = file_get_contents("http://website.com");
    preg_match("#<dt>Seeders:<\/dt>\s*<dd>(.*)<\/dd>#iU", $data, $match1);
    preg_match("#<dt>Leechers:<\/dt>\s*<dd>(.*)<\/dd>#iU", $data, $match2);
    echo $match1[1]; //seeders
    echo $match2[1]; //leechers
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic