Here is an example using phpQuery-one-file for ZIP query; the Curl part is not included as the focus is on using phpQuery; this is one of several possible solutions.
phpQuery: https://code.google.com/p/phpquery/
$body = $client->send($request)->getBody(); //Aqui seria seu HTML
//Inclusão do phpQuery
if (!method_exists('phpQuery', 'newDocumentHTML'))
require_once __DIR__ . DIRECTORY_SEPARATOR . 'phpQuery-onefile.php';
//Inicialização do documento, substitua $body pela sua variável contendo o HTML;
$doc = \phpQuery::newDocumentHTML($body, $charset = 'utf-8');
$resultados = [];
//Itera sobre as linhas da tabela;
foreach(\phpQuery::pq('table[cellpadding="5"]')->find('tr') as $linha) {
$dados = [];
foreach(\phpQuery::pq($linha)->find('td') as $coluna) {
$valor = htmlspecialchars_decode(trim(preg_replace('/\s+/', ' ', \phpQuery::pq($coluna)->html())));
$dados[] = $valor;
}
$dadosFinal['logradouro'] = $dados[0];
$dadosFinal['bairro'] = $dados[1];
$dadosFinal['localidade'] = $dados[2];
$dadosFinal['uf'] = $dados[3];
$dadosFinal['cep'] = $dados[4];
$resultados[] = $dadosFinal;
}
return $resultados;
Applying your need, would do something like:
//Inclusão do phpQuery
if (!method_exists('phpQuery', 'newDocumentHTML'))
require_once __DIR__ . DIRECTORY_SEPARATOR . 'phpQuery-onefile.php';
//Inicialização do documento, substitua $body pela sua variável contendo o HTML;
$doc = \phpQuery::newDocumentHTML($body, $charset = 'utf-8');
foreach(\phpQuery::pq('ul#lista_municipios')->find('li') as $linha) {
$valor = htmlspecialchars_decode(\phpQuery::pq($linha)->html());//item2
$valorAttr = htmlspecialchars_decode(\phpQuery::pq($linha)->attr('href')); //Item1 (valor do href)
$item1 = explode('|', $valorAttr)[1]; //mantive $valorAttr caso você precise.
}
In the end it would need tests and adaptations for your need;
If I understand correctly, you can use phpQuery, it simulates jquery only in php...
– Rafael Withoeft
Think I can get to the goal easier using phpQuery?
– Marcos Vinicius
It is one of the alternatives, I think it is well of personal opinion this choice, I will put an example that I used in ZIP consultation for you to analyze...
– Rafael Withoeft