#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Posts
    21
    Rep Power
    0

    Read Javascript Object


    I'm able to get an external sites HTML code. Inside that code they have a javascript code which has a JS object called myListItems.

    I know how to get the HTML via file_get_contents but how canI scrape the JS code so I can use it?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,470
    Rep Power
    653
    Essentially you can't. Javascript is client side so you cannot know what is happening when executed by the user/browser. You can pull the script itself depending on if it is embedded in the HTML or pulled from a file. You would have to analyze the <javascript> tag(s) to determine which. After that you would need to know what the user/browser actions are to execute it. Finally you would have to emulate its execution on the server using the same conditions as the user/browser. All of that is virtually impossible.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Location
    Pakistan
    Posts
    38
    Rep Power
    1
    <p id="demo"></p>

    <script>
    // Create an object:
    var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};

    // Display some data from the object:
    document.getElementById("demo").innerHTML =
    person.firstName + " is " + person.age + " years old.";
    </script>
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,470
    Rep Power
    653
    That does not answer the OP. As I said it is not possible.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,470
    Rep Power
    653
    That does not answer the OP. As I said it is not possible.

    P.S. Please use code tags when posting non-PHP code.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo