0
Well, I have the following code:
<?php
$url = 'https://www.zerozero.pt/edicao.php?id_edicao=135716';
$str = '';
$html = file_get_contents($url);
//debug purposes
//$html = '<div id="pagina">foo</div>';
$doc = new DOMDocument();
$doc->strictErrorChecking = false;
@$doc->loadHTML( $html );
$div = $doc->getElementById( 'edition_table' );
$str = $div->nodeValue;
echo $str;
?>
This code takes all data from the site’s classification table: https://www.zerozero.pt/edicao.php?id_edicao=135716
And return the following:
It returns me all the values, but I intended to separate each value obtained by a space. That is to separate each value he pulls to get deferential:
Example: P J V E D GM GS DG 1 National 50 24 etc...
I wanted to make my code return like this.
How can I do?
IF you’re already using DOM why use EXPLODE? Use DOM to get the TR and then to get the TD.
– Guilherme Nascimento
Another thing, do not use error_reporting with 0, it is not to hide errors, by the way nor errors should appear, if it appears is because there is something wrong, I recommend you read: Why use error_reporting with display_errors and display_startup_errors?
– Guilherme Nascimento
As it would be in the case with the DOM?
– Gonçalo
Use https://www.php.net/manual/domdocument.getelementsbytagname.php or learn Xpath, ps: Without wanting to jab, on my FW I created a CSS Selector Xpath Converter to use with PHP DOM: https://github.com/inphinit/inphinit/wiki/QuerySelector-%28selectors-CSS%29-com-PHP#reading-a-p%C3%A1gina-external, of course you’ve already started a project in pure php or another framework, but it’s just an indication.
– Guilherme Nascimento
I will edit the question, I did it only with the DOM, but I still can not do what I want...
– Gonçalo
Test your code over and over again and you will see that the return is empty. It seems to me that the website you are trying to pull the data from does reCaptcha checking. This means that without reCaptcha validation, the table is not loaded by
getElementById( 'edition_table' )
.– Sam
Or he uses cookie. No cookie he tries to do the reCaptcha check to avoid that which you are trying to do.
– Sam
I tested the code about 50x in a row and I didn’t get that problem, I don’t know if it has to do with the location...
– Gonçalo