so I've been working on a script for a while now and can't figure out one thing. For the site putlocker.com I want to generate a unique url for videos. So essentially it takes a standared url and from that I generate a direct url. I already post data and generate another link, in the new page there is another link that is the actual video link. However, this URL changes with every IP Address. The only way I figured it would work is to load the $search2url in an iframe and get the source of the iframe which I can then parse. However, I realized that this is not possible because it is not on my domain. If there is a way I can do that or any other way I can load the $search2url and parse the unique link please let me know. Thanks!
If you run the script on a server and try to play the video, the video won't play. However, if you go to the link from the start the video plays.
<?php
$url = "http://www.putlocker.com/file/2CE47CB3D2292208";
$contents = file_get_contents($url);
$find = strpos($contents, '<input type="hidden" value="');
$part1 = substr($contents, $find+28);
$hash = substr($part1, 0, strpos($part1, '"'));
$postdata = http_build_query(
array(
'hash' => $hash,
'confirm' => 'submitButton'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
$url1 = substr($result, strpos($result, "/get_file.php?"));
$url2 = substr($url1, 0, strpos($url1, "'"));
$search2url = "http://www.putlocker.com$url2";
$res2 = file_get_contents($search2url);
$firstfinal1 = substr($res2, strpos($res2, 'url="')+5);
$finalmediaurl = substr($firstfinal1, 0, strpos($firstfinal1, '"'));
//echo $finalmediaurl;
echo $result;
?>
Related
I am trying to run a script that will search Healthline with a query string and determine if there are any search results, but I can't get the contents with the query string posting to the page. To search for something on their site, you go to https://www.healthline.com/search?q1=search+string.
Here is what I tried:
$healthline_url = 'https://www.healthline.com/search';
$search_string = 'ashwaganda';
$postdata = http_build_query(
array(
'q1' => $search_string
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$stream = stream_context_create($opts);
$theHtmlToParse = file_get_contents($healthline_url, false, $stream);
print_r($theHtmlToParse);
I also tried to just add the query string to the url and skip the stream, amongst other variations, but I'm running out of ideas. This also didn't work:
$healthline_url = 'https://www.healthline.com/search';
$search_string = 'ashwaganda';
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Content-Type: text/xml; charset=utf-8"
)
);
$stream = stream_context_create($opts);
$theHtmlToParse = file_get_contents($healthline_url.'&q1='.$search_string, false, $stream);
print_r($theHtmlToParse);
And suggestions?
EDIT: I changed the url in case someone wants to look at the search page. Also fixed the query string. Still doesn't work.
In response to Ken Lee, I did try the following cURL script that also just returns the page without search results:
$healthline_url = 'https://www.healthline.com/search?q1=ashwaganda';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $healthline_url);
$data = curl_exec($ch);
curl_close($ch);
print_r($data);
Healthline does not load the search result directly. It has its search index stored in Algolia and made extra javascript calls to retrieve the result. Therefore you cannot see the search result by file_get_content.
To see the search result, you need to run a browser simulator that simulates a javascript-capable browser to properly run the site page.
For PHP developers, you may try using php-webdriver to control browers through webdriver (e.g. Selenium, Chrome + chromedriver, Firefox + geckodriver).
Update: Didn't know that the target site is Healthline. Updated the answer once I found out.
I want to read an external site after submit code with captcha. But using (PHP) file_get_contents the captcha is loaded 2 times, so its wrong.
The Form load an image to solve the captcha and sent via POST to the original site that show the result. Normally I solve the captcha and than, in the new site, I read (with my eyes) the content.
Now I want to let PHP read the content. I always solve first the captcha (in my page) and than send it to the other site and let (php) "file_get_contents" read the content.
HERE MY CODE..
<?php
$captcha = $_POST["captcha"];
?>
<html>
<form method="post" action="(this page)">
<img src="remote-captcha"><input type="text" name="captcha">
<submit>
<?php
$postdata = http_build_query(
array(
'captcha' => $captcha
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://www.form-page', false, $context);
$search = '/<div class="myclass">(.*)<\/div>/';
preg_match($search, $result, $show);
echo $show[0];
?>
At this point the form is loaded 2 times so the captcha is wrong.
Can someone help me?
I want to use sci-hub.cc to download scientific papers, but it is in russian and it is not easy to use.
It has a textfield for enter DOI or paper link.
Now, I want to make a website that, when users insert paper link, send this link to sci-hub as a query and then download it. How can I do this in php?
Thanks a lot.
i dont know how your page is working but what you looking for is a "POST" Request with.
The code below "does" the same if you type in something in the field on your page:
<php
$url = 'http://sci-hub.cc/';
$data = ['Request'=>'TEXT FOR FIELD'];
$options = array('http' => array(
'method' => 'POST',
'content' => http_build_query($data),
'header'=> "Content-Type: application/x-www-form-urlencoded \r\n")
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
?>
After a long research on internet , I have found a method that seems to work , but not on the website I want.
<?php
$username = '';
$password = '';
$url = 'https://web.esme.fr/pscripts/bsp';
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
));
$data = file_get_contents($url , false, $context);
echo($data);
?>
I have tried this on another part of the website and it works , but on the page I want $data contains nothing !!!!
I know that sometimes this url asks 2 times the authentication , sometimes not.
Any suggestion ?
Thank you
I've been trying to get the pastebin API to instead of telling me the pastebin link , just output the raw data. The PHP code is this :
<?php
$api_dev_key = 'Stackoverflow(fake key)';
$api_paste_code = 'API.'; // your paste text
$api_paste_private = '1'; // 0=public 1=unlisted 2=private
$api_paste_expire_date = 'N';
$api_paste_format = 'php';
$api_paste_code = urlencode($api_paste_code);
$url = 'http://pastebin.com/api/api_post.php';
$ch = curl_init($url);
?>
Normally this would upload the $api_paste_code into pastebin , showing up like pastebin.com/St4ck0v3RFL0W , but instead I want it to generate the raw data.
The raw data link is http://pastebin.com/raw.php?i= , can anyone help?
Reference : http://pastebin.com/api
As far as I see, the response contains the Pastebin URL generated when the content is created. An Url like this:
http://pastebin.com/UIFdu235s
So what you only need is to get rid of "http://pastebin.com/" doing:
$id = str_replace("http://pastebin.com/", "", $url_received_on_last_step);
And then, append it to the raw url you provided:
$url_raw = "http://pastebin.com/raw.php?i=".$id;
And you'll get the raw data.
First off, please note that you must send a POST request to the pastebin.com API, not GET. So don't use urlencode() on your input data!
To get the raw paste url from the page url, you have several options. But the easiest is probably:
$apiResonse = 'http://pastebin.com/ABC123';
$raw = str_replace('m/', 'm/raw.php?i=', $apiResponse);
Finally, here is a complete example:
<?php
$data = 'Hello World!';
$apiKey = 'xxxxxxx'; // get it from pastebin.com
$apiHost = 'http://pastebin.com/';
$postData = array(
'api_dev_key' => $apiKey, // your dev key
'api_option' => 'paste', // action to perform
'api_paste_code' => utf8_decode($data), // the paste text
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "{$apiHost}api/api_post.php",
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query($postData),
));
$result = curl_exec($ch); // on success, some string like 'http://pastebin.com/ABC123'
curl_close($ch);
if ($result) {
$pasteId = str_replace($apiHost, '', $result);
$rawLink = "{$apiHost}raw.php?i={$pasteId}";
echo "Created new paste.\r\n Paste ID:\t{$pasteId}\r\n Page Link:\t{$result}\r\n Raw Link:\t{$rawLink}\r\n";
}
Running the above code, outputs:
c:\xampp\htdocs>php pastebin.php
Created new paste.
Paste ID: Bb8Ehaa7
Page Link: http://pastebin.com/Bb8Ehaa7
Raw Link: http://pastebin.com/raw.php?i=Bb8Ehaa7