Why is PHP Simple HTML DOM Parser unable to capture the contents of a tag from certain URL's?

StackOverflow https://stackoverflow.com/questions/11772214

  •  24-06-2021
  •  | 
  •  

Question

I'm using PHP Simple HTML DOM Parser to get the contents of the first <h1> tag on different webpages. The script works great most of the time, but on some webpages my script just kind of 'hangs up'. The script stops, without completing the code that comes after what I have listed below. I looked at the source for the pages that don't work, but there is nothing particularly different about the <h1> or its contents. Is there a way I can get this to work for all possible URL's, and if not, how can I fix my script so it won't hang up for the URL's that don't work?

include_once( 'simple_html_dom.php');
$html = file_get_html($webpage);
$element = $html->find('h1', 0);
$element = strip_tags($element);
Was it helpful?

Solution

I never got a response, but it appears the answer is to use cURL to get the contents of the url, then get the tag info with PHP Simple HTML DOM Parser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top