How to copy everything from a website and save to a txt file

Asked

Viewed 165 times

1

1 answer

2


You can do with Curl like this:

<?php
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://steamcommunity.com/profiles/76561198337627631/inventory/json/730/2/');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'MOZILLA YOOO');
$page = curl_exec($curl_handle);
curl_close($curl_handle);
$f_handler = fopen('test.txt', 'w');
fwrite($f_handler, $page);

And with file_get_contents:

<?php
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "User-Agent: Mozzila yooo\r\n"
  )
);
$context = stream_context_create($opts);
$page = file_get_contents('http://steamcommunity.com/profiles/76561198337627631/inventory/json/730/2/', false, $context);
$f_handler = fopen('test.txt', 'w');
fwrite($f_handler, $page);
  • Miguel, with file get Contents, it’s not working.

  • What a mistake it makes?

  • Just don’t write anything down.

  • And Curl writes down?

  • No, you’re not writing.

  • Do you have a visual on the bugs? what gives me sometimes is error 429: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes which are too many request from the same client. Try changing the url, or wait a few minutes

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.