class DomDocumentParser {
private $doc;
public function __construct($url) {
$options = array(
'http' => array('method' => "GET", 'header' => "User-Agent: YourBotName/0.1\n")
);
$context = stream_context_create($options);
$this->doc = new DomDocument();
@$this->doc->loadHTML(file_get_contents($url, false, $context));
}
public function getlinks() {
return $this->doc->getElementsByTagName("a");
}
}
function extract_href_links($url) {
$parser = new DomDocumentParser($url);
$allLinks = $parser->getLinks();
foreach ($allLinks as $link) {
$href = $link->getAttribute("href");
echo $href . "<br />";
}
}
$url = "https://www.collectivesolver.com/";
extract_href_links($url);
/*
run:
./26670/how-to-check-if-a-string-is-rotation-of-another-string-in-java
./26670/how-to-check-if-a-string-is-rotation-of-another-string-in-java?show=32942#a32942
./user/avibootz
./tag/JAVA
./32936/how-to-remove-specific-char-from-string-using-stringbuilder-in-java
./32936/how-to-remove-specific-char-from-string-using-stringbuilder-in-java?show=32937#a32937
./user/avibootz
./tag/JAVA
./32934/how-to-remove-specific-char-from-string-in-java
./32934/how-to-remove-specific-char-from-string-in-java?show=32935#a32935
./user/avibootz
./tag/JAVA
./32932/how-to-convert-an-array-of-integers-to-string-in-java
./32932/how-to-convert-an-array-of-integers-to-string-in-java?show=32933#a32933
./user/avibootz
./tag/JAVA
./32930/how-to-convert-an-array-of-strings-to-string-in-java
./32930/how-to-convert-an-array-of-strings-to-string-in-java?show=32931#a32931
./user/avibootz
./tag/JAVA
./32926/how-to-stop-execution-of-a-program-in-php
./32926/how-to-stop-execution-of-a-program-in-php?show=32929#a32929
./user/avibootz
./tag/PHP
...
*/