html - PHP Fatal error: Call to a member function hasAttribute() on a non-object -
Trying to get the rating
I get an error on line 18 error message says "PHP Fatal Error: Call a member function atitudit () on a non-object "
I've included all the PHP codes that I'm using to get ratings.
public function getSiteAdvisor ($ domain) {try {$ callback_url = "http://www.siteadvisor.com/sites/" $ domain; $ Curl_response = $ this- & gt; Curl- & gt; Get ($ callback_url); If ($ curl_response-> header ['status-code'] == "200") {libxml_use_internal_errors (TRUE); $ This- & gt; Dom_doc-> LoadHTML ($ curl_response); Libxml_use_internal_errors (FALSE); $ Xpath = new DOMXPath ($ this- & gt; dom_doc); $ Tmp = $ xpath- & gt; Query ('/ html / body // div [@ id = "site bill"] // img') - & gt; Item (0); If ($ tmp-> hasitivity ('src')) {$ tmp = $ tmp- & gt; GetAttribute ('src'); If (stripes ($ tmp, "green")! == incorrect) {$ siteadvisor_rating = 1; } Otherwise (strippos ($ tmp, "yellow")! == incorrect) {$ siteadvisor_rating = 2; } Otherwise (strip ($ tmp, "red")! == incorrect) {$ siteadvisor_rating = 3; } And {$ siteadvisor_rating = 0; }} And {$ siteadvisor_rating = 0; }} And {$ siteadvisor_rating = 0; } $ Response = array ('status' = & gt; 'success', 'data' = & gt; array ('siteadvisor' = & gt; (int) $ siteadvisor_rating); } Hold (exception $ e) {$ response = array ('condition' = & gt; 'error', 'msg' = & gt; $ e- & gt; get message ()); } $ Response; } I think you have a problem with the xpath query (like Gordon has said ): And instead target the alt = ""
attribute.
$ domain = 'google.com'; $ Callback_url = "http://www.siteadvisor.com/sites/" $ domain; // I know that you know that you can only adjust $ curl_response = file_get_contents ($ callback_url); $ Dom = new DOMDocument (); Libxml_use_internal_errors (true); $ Dom- & gt; LoadHTML ($ curl_response); Libxml_use_internal_errors (true); $ Xpath = new DOMXpath ($ dom); $ Siteadvisor_rating = null; $ Img_rating = $ xpath- & gt; Query ('// div [@ id = "site bill"] / div / img'); If ($ img_rating-> gt; length & gt; 0) {// haystack if ($ img_rating-> item (0) -> gt; heativity ('alt')) {$ img_rating = $ img_rating-> ; Items (0) - & gt; GetAttribute ('alt'); } Otherwise ($ img-> item (0) - & gt; hatatribubut ('src')) {$ img_rating = $ img_rating-> Items (0) - & gt; GetAttribute ('src'); } If (strips ($ img_rating, 'green')! == incorrect) {$ siteadvisor_rating = 1; } Otherwise (strips ($ img_rating, '')! == incorrect) {$ siteadvisor_rating = 2; } Otherwise (strippos ($ img_rating, 'red')! == incorrect) {$ siteadvisor_rating = 3; } And {$ siteadvisor_rating = 0; } Echo $ siteadvisor_rating; // Google should have 1 :)} and {// no node was found}
Comments
Post a Comment