-1

I am having trouble requesting the contents of an URL in PHP. I've tried cURL and get_file_contents, but they return this:

<!DOCTYPE html>
<html>
<head>
  <title>Pd3</title>
  <link rel="stylesheet" media="all" href="/assets/application-368cb37ed2535f71ae87f60f8f82622cc73d6d29c6deb2acf95e2cec635b7408.css" data-turbolinks-track="true" />
  <script src="/assets/application-066584cdb59095baa3df04c44046e204dcdd182c5a470cc26f2edb8e9eb7c892.js" data-turbolinks-track="true"></script>
  <meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="v6QnPq6M6ZjiE9OCef0t31c2cwNYgp8W9hm4W8SxRkUYhSItyDeM5QvD/bflS22PcC4yx1jTFIixyRCwAiINTA==" />
</head>
<body>

<script src="/assets/pd3/vendor-a13cc6fe33668e1507bd5d4561f1b9f2d0b1840eba080e8c1163e50b370a449a.js"></script>
<script src="/assets/pd3/pd3-8b89ef5b8b417522ab05e24635511996d570c00af8ad2f2ae9715226d88f4db9.js"></script>
<link rel="stylesheet" media="screen" href="/assets/pd3/vendor-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css" />
<link rel="stylesheet" media="screen" href="/assets/pd3/pd3-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css" />


</body>
</html>

When browsing the site normally, the source looks like this (which contains the data I need):

   {"user":{"id":"873752","userid":"873752","username":"TomTastic","registered":"2015-09-17T10:34:24.412Z","wagered":50019914433,"profit":328426591.8411,"bets":39696,"wins":19709,"losses":19987,"win_risk":99523652,"lose_risk":98590521,"messages":769}}

I did some fiddeling around in Chrome developer tools, and I think that the content I need is from an XMLHttpRequest, called by one of the JavaScripts. Referencing the scripts with the full URL didn't work. I've tried using simplexml_load_file(), but I don't really understand how it works (and I think I don't need it) Please help me, I am about to rip my hair out. The website is https://pd3.co/users/TomTastic (some random user to test with) Thanks!

  • 1
    I think you need to provide a little more information about what you're trying to do. I'm guessing this is a single-page JS app, which is accessing some kind of API (REST?) to get the data that's rendered to the page. For whatever you're trying to do, I'd guess it would be easier if you can access the API directly. Are you able to do that? – DaveyDaveDave Mar 23 '16 at 14:29

1 Answers1

0

You have to set the value of the Accept header of your request to application/json.

Here you can see how to do it with curl: How to send a header using a HTTP request through a curl call?

Community
  • 1
  • 1
Tobias Xy
  • 1,946
  • 15
  • 18