Anthony Jesmok
Anthony Jesmok

Reputation: 459

Get a JavaScript variable from a remote page?

I am currently working on developing an API for a company. Specifically, here's my issue. They have JavaScript arrays on a webpage that their webmaster updates. I have to pull these arrays into either a simple JS script or PHP file and get the contents of these arrays, which I can then arrange according to the API's specifications and output it as JSON.

How do I pull a JavaScript variable in from a remote page in either PHP or jQuery/JS and make it usable for other applications?

No, I don't have access to the company's website. I have to work off of page scraping for this one.

Thank you!

Upvotes: 1

Views: 1614

Answers (2)

user1781710
user1781710

Reputation:

If I where you, I’d use PHP to file_get_contents (or CURL depending on the server config) the page and then parse it based on whatever the markers are to find the value of the variable, assuming it’s written out to the page in the first place.

Upvotes: 0

Jake
Jake

Reputation: 4234

You can't access private javascript variables remotely, due to Same origin policy. They would have to output the arrays in some kind of readable format that you could access using AJAX, probably as JSON.

Edit: As mentioned below, if the array is explicitly defined as text in a javascript file, you could grab the contents of that file using cURL in PHP

Upvotes: 1

Related Questions