1

i have a code that is working

$html = file_get_contents('https://www.imdb.com/');
echo $html;

also this code working too

$html = file_get_contents('https://www.google.com/');
echo $html;

but its not working with some urls like this one:

$html = file_get_contents('https://www.rottentomatoes.com/');
echo $html;

and i get this error

Warning: file_get_contents(https://www.rottentomatoes.com/tv/friends): failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

and i don't understand why this happening? and website loads in browser with no problem and no need for vpn (but some other url might need).

i also used Simple HTML DOM Parser and in 1.9 version i get this error and in 2.0RC2 version i get empty $html and NULL value.

can someone help me please?

6
  • possible duplicate Commented Nov 3, 2020 at 10:17
  • 1
    @berend its kinda similar but their answer based on luck! Commented Nov 3, 2020 at 10:22
  • Web scraping can be a complex task depending on the site and the solutions it implements to prevent scraping, among possible cases: some sites may need some cookies to work as a protection (possible to enable them with curl), they can also check if the request comes from a browser, allow only some methods (eg POST or GET), or if they render the page with a JS framework you could have an incomplete result.. adding details could help people to properly answer you Commented Nov 3, 2020 at 10:40
  • 1
    @Kaddath thank you for useful information. before going forward i kinda wonder why this exact same code works for my friend in another country and not 1 every time he runs it and not working for me? maybe depends on internet connection? i don'n know Commented Nov 3, 2020 at 10:46
  • 1
    @Kaddath thank you i'll try that but not much information about webscraping rottentomatoes Commented Nov 3, 2020 at 11:02

1 Answer 1

1

You can't use file_get_contents() function on any website! Currently the 2nd website https://www.rottentomatoes.com/ is refusing your connection

Please read more on how to use file_get_contents

Sign up to request clarification or add additional context in comments.

16 Comments

so what about simple-html-dom? i also tested php guzzle and how can i fix this problem?
but this is kinda weird, i have a friend and he just copy past my code and its works for him how they not block his request!
but he is in a different country
@BurhanKashour as i try everything i know and then ask my question here. i also tested cUrl and set up the header etc stuff but that didn't work either
@BurhanKashour i don't remember really maybe this error. but i will test again
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.