Get specific content from an external url - PHP

get html content from url php
php file_get_contents($url)
php file_get_contents post
php get url
file_get_contents not working
file_get_contents() returns false
php file_get_contents https
php read file

I am trying to get the direct download link from Google Drive, so I want to get specific content from external url.

Example: visit x link and get the url from this div or from this class! I think that this is possible, but I don't know how to do it.

 $dom = new DOMDocument;
 libxml_use_internal_errors(true);
 $dom->loadHTMLFile('https://drive.google.com/uc?id=12ejMrVziFpjcEpG9A2Ks4yoNDJ9qz0B5&export=download');
 $DOMxpath = new DOMXPath($dom);
 $DivContent = $DOMxpath->query("//div[@id='uc-download-link']");
 $bigDiv = $DivContent;
 $link = $bigDiv->find('a');
 echo $link->href . '<br>';

Is that possible with PHP or JavaScript?

Sure, it can be done easily with php's file_get_contents, DOMDocument and DOMXPath.

The following example gets the HREF value from the 'Stack Overflow' logo's <a> tag, which has the class -logo js-gps-track:

$html = file_get_contents('http://stackoverflow.com/');
$dom = new DOMDocument();
libxml_use_internal_errors(true);

$dom->loadHTML($html);
$xpath = new DOMXPath($dom);

// find the element whose href value you want by XPath
$nodes = $xpath->query('//*[@class="-logo js-gps-track"]');

foreach($nodes as $href) {
    // print out the href value
    echo $href->getAttribute( 'href' ); 
}

Obviously you'd just need to amend the URL and the XPath for your specific use case.

file_get_contents - Manual, return array ('content'=>file_get_contents ($url, false, stream_context_create (​array Keep in mind that if you use a URL as the filename attribute, and the external NTLM authentication, certain applications will not get out of the network. This is an easy way to trigger scripts by listening for POSTs. I simply point a service's webhook url to the script, which file_get_contents("php://input"), cast to an array, and then simplexml_load_string() to parse it and use one of the keys' data as the parameter for my script.

Would it be fair to say that you're trying to scrape links from an external page? If so, there's very popular JS package called Cheerio, which allows you to access elements the same way as jQuery. It runs on Node https://www.npmjs.com/package/cheerio but it seems to be available via CDN at https://www.jsdelivr.com/package/npm/cheerio

Six Ways of Retrieving Webpage Content In PHP, 1. file() <? php $url='https://oscarliang.com'; // using file() function to get content $lines_array=file($url); // turn array into one variable $lines_string=implode('',$lines_array); //output, you can also save it locally on the server echo $lines_string; ?> But while writing a script you may often face challenge to fetch the contents from the URL. Some programmers use file_get_contents () function of PHP to get the data from the URL, but by default the http is not supported in the argument of this function. So to get the contents from a URL you have to make a curl request.

Definitely possible with both PHP & JavaScript. Thing is, how you want to approach it. To get the download link from drive by parsing DOM, I will use these packages:

PHP : simple_html_dom package

NODE JS : cheerio

PYTHON : simple request library with bs4

You can just filter with find() to locate download link text section and grab it finally with plaintext() method of simple_html_dom

Example

include('simple_html_dom.php');

$html = file_get_html('gdriveurl');

$target = $html->find('a'):

echo $target->href (This is the download link )

Another easiest solution is xpath

How can i pull content from another website? - PHP, For example i have my own website, and i want to pull content from In Javascript you can use Ajax to send your request and POSt/GET data. In PHP, you can use [URL=“http://www.php.net/manual/en/book.curl.php”]cURL or the PECL First of all, this setting DOES NOT allow you to include() external urls  PHP 5 - Using an external URL with the function include Latest update on February 5, 2012 at 07:34 PM by Paul Berentzen . By default, in PHP 5 and the latest version, the option to include an external URL with the function include is disabled.

PHP file_get_contents() Function, This function is the preferred way to read the contents of a file into a string. It will use memory mapping techniques, if this is supported by the server, to enhance  The fact that the very first example for the function in the manual shows how to get the contents of an external URL would seem to disprove your point. hbsooner September 5, 2014, 9:32am #17

jQuery AJAX load() Method, It is also possible to add a jQuery selector to the URL parameter. If the load() method has succeeded, it displays "External content loaded successfully!", and if​  Posted in PHP Tutorials Tagged file upload from url, php file upload from external url, php script image upload from url, simple upload script Post navigation How to send XML data using PHP and CURL?

Possible to only load specific div of a website?, You won't be able to manipulate the URL to get only a portion of the page. So what you'll want to do is grab the page contents via the server-side language of  PHP - Get image data from URL and display it - Forum - Courses and Tutorials I use the following PHP code to get the image data from an external URL

Comments
  • Thanks for your help, so in my case, the url is this https://drive.google.com/uc?id=12ejMrVziFpjcEpG9A2Ks4yoNDJ9qz0B5&export=download and the class name is jfk-button-action and after this class, is the download url that what i want to get, after I put your code, I tried to get the link <?php echo $href;?> but is not working!
  • If you do a file_get_contents on that URL, you'll see it only retrieves the file data. It's not an HTML URL
  • so how i can get, the download link can you show full code, thanks
  • now I have test to get the Stack Overflow logo, but is not working, that get the Stack Overflow Url stackoverflow.com not the logo url!
  • The URL you provided is the direct download link. I can't tell you what the URL is that would contain that link - you'd have to find that page and go from there. The example I pasted in for stackexchange works - the URL on the logo is 'stackexchange.com'
  • Thanks for your help, but i need some code ful code i can't do that by my self, thanks again
  • please, can you show me a code? to do this function? thanks
  • Added in answer.
  • somthing still missing, ca you show full code thanks again
  • You will have to download that library from SourceForge and replace ^gdriveurl with your Google drive url. Let me know if any further issue