Menu

#56 How to avoid break on 404 errors?

v1.0_(example)
closed
None
1
2022-04-09
2020-10-15
JensHK
No

How do I avoid 404 breaks? I am still using 1.5 - but a test with 1.9 give same error. I use: $html = file_get_html($url);

Error:
Warning: file_get_contents(http://www.apple.com/br/shop/buy-iphone/iphone-12-pro): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in .......

The program breaks at that point and I need to remove the URL. After that it works (to the next bad URL). Is there a way to just ignore bad URLs?

Discussion

  • JensHK

    JensHK - 2020-10-16

    Update: I did some recode. Instead of file_get_html($url)I used cURL to get the website data, that check for a keyword with strpos()and then prcessed with str_get_html($body)

    Perfect workaround for me.

     

    Last edit: JensHK 2020-10-16
  • LogMANOriginal

    LogMANOriginal - 2022-04-09
    • status: open --> closed
    • assigned_to: LogMANOriginal
     
  • LogMANOriginal

    LogMANOriginal - 2022-04-09

    Good to know you found a solution :)

     

Log in to post a comment.