php - file_get_html() not working? -


I am trying to get page title and meta description data, to provide the URL of the target page, but file_get_html () always returns the wrong value any suggestions? By the way I've enabled the PHP extension php_openssl

  & lt ;? Includes php ("inc / simple_html_dom.inc.php"); $ Content = file_get_html ("https://www.facebook.com"); If ($ content = FALSE) / / always leaves the condition, then the condition {foreach ($ contents- & gt; $ as element ('title')) {$ title = $ element-> Plain text; } foreach ($ contents-> find ('meta [description]')) as $ element {$ meta_description = $ element-> Plain text; } $ Output = array ('title' = & gt; $ title, 'meta' => $ meta_description); Echo json_encode ($ output); } Else {echo "Content could not be loaded"; }? & Gt; Update:  

Then file_get_html () works just fine but Facebook Update has any idea about dealing with browser messaging?

  & lt; php $ ch = curl_init ('https://www.facebook.com/'); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, true); / * * XXX: This is not "OK" for your problem, it's a work-around You should fix * your local CA * / curl_setopt ($ CH, CURLOPT_SSL_VERIFYPEER, incorrect); / * Set a browser UA so that we update * / curl_setopt ($ CH, CURLOPT_USERAGENT, 'Mozilla / 5.0 (Windows NT 6.1; WOW64) Apple WebKat / 537.36 (KHtml, Geeko) Chrome / 34.0.1847.116 Safari Not stated. / 537.36 '); $ Res = curl_exec ($ ch); If ($ res === incorrect) {dead ('error:' .cll_uper ($ ch)); } Curl_close ($ ch); $ d = new DOMDocument (); @ $ D & gt; loadHTML ($ race); $ Output = array ('title' => gt; '', 'meta' = 'gt;' '); $ X = new DOMXPath ($ d); $ Title = $ x-> Query ("// title"); If ($ Title-> Length> gt; 0) {$ Output ['Title'] = $ Title-> Items (0) - & gt; TextContent; } $ Meta = $ x- & gt; Query ("// meta [@name = 'description']"); If ($ meta-> Length> gt; 0) {$ Output ['Meta'] = $ Meta- & gt; Items (0) - & gt; getAttribute ('content'); } Print_r ($ output); ? & Gt;   

It displays:

 Array ([title] => Welcome to Facebook - Sign In, Sign Up or Learn More [Meta] = & gt; Facebook, people who work together with people and social utilities who connect with others, use Facebook to work with friends, upload unlimited number of photos, post links and videos, and Learn more about the people they find Areas are.)   

Comments

Post a Comment

Popular posts from this blog

jasper reports - How to center align barcode using jasperreports and barcode4j -

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -