I have a problem with my curl :
I connect to a page with CURL. then I redirect myself to a page that is available when you are connected. and then I would like to retrieve information on this page. But how can I do to get the html code? I have the page that is displayed, but I can't get the source code for scrap
$url = "https://www.mywebsite.com/porte_transferer.php";
curl_setopt ($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
return true with var dump
with that, i see the page, but idk how recover html for scrap my information
Thank for your help
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
if(curl_error($ch)) {
fwrite($fp, curl_error($ch));
}
curl_close($ch);
fclose($fp);
source
Related
In this script curl is working fine. $output has the page but when I try to echo its source code it displays nothing. I think it has something to do with page headers. Any help!!
header('content-type:text/plain');
$ch = curl_init();
$url = "https://www.amazon.com/gp/css/shiptrack/view.html/ref=TE_SIMP_typ?ie=UTF8&addressID=olqnkqjstjp&latestArrivalDate=1483848000&orderID=103-0753412-5410653&shipmentDate=1483706902&orderingShipmentId=4160817392100&packageId=1";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
I have modified your code..
Try this.
Remove
header('content-type:text/plain');
and replace your code with mine.
$ch = curl_init();
$url = "https://www.amazon.com/gp/css/shiptrack/view.html/ref=TE_SIMP_typ?ie=UTF8&addressID=olqnkqjstjp&latestArrivalDate=1483848000&orderID=103-0753412-5410653&shipmentDate=1483706902&orderingShipmentId=4160817392100&packageId=1";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
EDIT
Since you want ctrl+u
Here is the PHP code to fetch the html source code of any website specified. fopen function is used to open the website URL. stream_get_contents is used to read the opened URL. The fetched code is displayed inside a textarea.
$domain = 'https://www.amazon.com/gp/css/shiptrack/view.html/ref=TE_SIMP_typ?ie=UTF8&addressID=olqnkqjstjp&latestArrivalDate=1483848000&orderID=103-0753412-5410653&shipmentDate=1483706902&orderingShipmentId=4160817392100&packageId=1';
$handle = fopen($domain, 'r');
$content = stream_get_contents($handle);
/**
// alternative to stream_get_contents
$contents = '';
while (!feof($handle)) {
$content .= fread($handle, 8192);
}
**/
fclose($handle);
/**
* print html content on textarea
*/
echo "<textarea rows='20' cols='80'>$content</textarea>";
output will be like this:
OR
Also if you want to manipulate the retrieved page somehow, you might
want to try some php DOM parser. I find PHP Simple HTML DOM
Parser very easy to use.
this code was working for a period of time pretty good:
<?php
$ch = curl_init("***");
$fp = fopen("example_homepage.html", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
but now it's giving me page with :" Object Moved This document may be found here"
i tried to solve it with "curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);" :
<?php
$ch = curl_init("***");
$fp = fopen("example_homepage.html", "w");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
but now it's giving me blank page, I'm doing something wrong? I tried some other things but it was always giving me blank one. I don't know much about programming, hope that you guys can help me
If you are not going to send any sensitive data, a quick fix would be to turn off the SSL verification,
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
I am trying to use PHP CURL to save this image to my computer, but isnt working, any help would be appreciated.
Image to Save:
https://s.yimg.com/aw/api/res/1.2/MRhsVBj10l4TrtNg5j7eBA--/YXBwaWQ9eXR3YXVjdGlvbnNlcnZpY2U7aD0xNTA7cT04NTtzcj0xLjI7c3M9MS4yO3c9MjAw/http://nevec-img.zenfs.com/prod/tw_ec05-7/258e866a-b39a-471d-8e6c-62801cbccd9d.jpg
My Curl function:
function grab_image($url,$saveto){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
($saveto);
}
$fp = fopen($saveto,'x');
fwrite($fp, $rawdata);
fclose($fp);
}
I am pretty sure the permission for the place to save to is 777 because I can save image from other website without any problem.
Thanks again
It's a HTTPS request, please add curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
If you want to know what's going on, add $errmsg = curl_error($ch); before curl_close, and then echo $errmsg;.
I want to save the below link's output to file.xml but it is not working for me. It just displays the output on another browser.
$url = 'http://www.forexwire.com/feed/full?username=alumfx&password=T7M9Exb4';
$fp = fopen (dirname(__FILE__). '/file.xml', 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
$ch->save('file.xml');
fclose($fp);
By default CURL's exec function returns the result as standard output. You need to add this to make it return the result as a string:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
then just save it into a variable
$output = curl_exec($ch);
//do whatever with the $output
So that the complete code snippet can look like this:
$ch = curl_init('http://www.forexwire.com/feed/full?username=alumfx&password=T7M9Exb4');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
$output = curl_exec($ch);
curl_close($ch);
file_put_contents('path/to/file', $output);
https://blog.onlywire.com/category/content-submission/feed/
This is my feed URL. For some reason, I am not able to parse it using PHP. What am I missing?
The script:
$ch = curl_init( $feed_curl );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
echo $data;
Try to see if you're getting any curl error - and don't forget to close the handler!
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return into a variable
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch); // run!
if($result === FALSE) {
var_dump(curl_error($ch));
}
else {
var_dump($result);
}
curl_close($ch);
Try specifying a file of root CAs:
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/your/cafile');
You can download a CA file from the curl website:
http://curl.haxx.se/docs/caextract.html