Error returning page with Curl + PHP

Asked

Viewed 332 times

0

I’m using the cUrl + PHP to open an external site, but when I try to do this it even loads normal but does not show the content I am in need of. No console of Chrome this error appears below and I imagine that is the reason:

Uncaught DOMException: Failed to set the 'domain' property on 'Document': 'siteexterno.com' is not a suffix of 'meudominio.com.br'.

Does anyone know how I can fix this? Remembering that I don’t have access to the external site.

Code

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://br.sportingbet.com/esportes-futebol/brasil-s%C3%A9rie-a/1-102-190183.html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1');
$html = curl_exec($ch);
curl_close($ch);

echo $html;

Updating

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://br.sportingbet.com/esportes-futebol/brasil-s%C3%A9rie-a/1-102-190183.html');
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1');
curl_setopt($ch, CURLOPT_PROXY, '217.70.67.34'); 
    curl_setopt($ch, CURLOPT_PROXYPORT, '8080');
    curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$html = curl_exec($ch);
curl_close($ch);

echo $html;
  • I think if you put the code beyond the error it might help

  • I updated above and inserted the code I use to access the site, including the site I’m trying to access.

  • what content you want that you’re not able to access?

  • If you open this address for example https://br.sportingbet.com/esportes-futebol/brasil-s%C3%A9rie-a/1-102-190183.html you will see at the center of the page the next games that will happen if you try to access using the cUrl will not have this area to show.

  • Probably because there must be a shipment via ajax, to do with CURL I never did, use phantomjs...

  • This has nothing to do with Curl. This error appears because you are trying to load content that is not allowed. The HTML you get from Curl is trying to get information via AJAX and obviously your domain is not authorized to get that information. That is, you (yousite.com) are trying to get information from outrosite.com and by CORS will not succeed. The way to pass this is precisely by using Curl, but in a smarter way, you should get all the content via Curl.

  • @Magichat Now I got confused, I’m using Curl to pull the site, as I would do with js?

  • @Inkeliz you’re opening a door for me and that’s very nice, but when you say smarter way what do you mean? Domdocument is an option?

  • Brother, I’ve been there and with Curl for me it was hard, so with phantomjs it’s easy, if you dominate and can simulate the requests of Ajax the heders the cookies and everything, you can do with Curl, I guess, but I never did... if @Inkeliz can give some tips will be worth to me too... let’s aguradar

  • You don’t know what goals you have with Curl. In general, what you need is to use Curl as a proxy. What you’re doing is just taking the home page. What you can do is use Curl as a proxy literally. The idea is that when the site requests a request to siteexterno.com/api/qlcoisa you change to seusite.com/api/qlqrcoisa and this page will call, via Curl, to siteexterno.com/api/qlcoisa. At the end, the customer will call for a page of your site, no error will be presented. And your site will call internally by an external site, via Curl.

  • @Inkeliz do not know if I am researching wrong but still unsuccessful

  • @Inkeliz put up the code as I searched, but he keeps giving me the same thing, which you think might be?

  • 1

    Is this the data you want to capture? https://br.sportingbet.com/services/CouponTemplate.mvc/GetCoupon?couponAction=EVENTCLASSCOUPON&sportIds=102&marketTypeId=&eventId=&bookId=&eventClassId=190183&sportId=102&eventTimeGroup=ETG_NextFewHours_0_0

  • That’s right, that’s the data I need.

  • Izzas, izazas, this is it... haha... Oh I will need to leave, but I leave a hint in python, but in the end you will see that level 3 is much easier... Good Luck;) http://docs.pyspider.org/en/latest/tutorial/AJAX-and-more-HTTP/ For me the best part of programming is the "break in the head", this kind of thing can’t be learned in a hurry... If you have already broken the cuckoo enough hj leave for tomorrow.. I will try to do with Curl and put an answer....

  • 1

    Vlw by the light, I will advance here. vlw!!

  • What I said was to use Curl as proxy and not using a proxy in Curl, it makes all the difference for you.

  • @Inkeliz really it makes all the difference, but I won’t lie that it keeps bugging my head kkkk

  • @Inkeliz you suggested it because you thought it was possible or is that what you said is possible?

  • It is something totally possible and is nothing "revolutionary". Searching quickly, has it and that, just the same idea, and the same name as "proxy".

Show 15 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.