PHP simple parsing HTML DOM
HackForum
PHP simple parsing HTML DOM | # |
| Zdravim osadenstvo.
Snazim sa zdokonalit v parshovani dat. Pouzivam PHP simple parsing HTML Dom. Jediny problem s cim si neviem dat radu su vstupne URL. Viem spracovat jednu ale nedary sa mi spracovat pole.
include_once('simple_html_dom.php');
// Create DOM from URL
$html = file_get_html('[link]');
$articles = array();
// Find all article blocks
foreach($html->find('div#uvod_cont') as $article) {
$item['title'] = $article->find('h1', 0)->plaintext;
$item['intro'] = $article->find('h2', 0)->plaintext;
$item['details'] = $article->find('iframe')->plaintext;
$articles[] = $item;
}
?>
Ako upravit script tak aby mi html resp. vstupne adresy bral s pola array = (www.1.sk,www.2.sk......)
Dakujem za kazdu radu (odpovědět) | |
|
|
re: PHP simple parsing HTML DOM | # |
| Tohle jsi myslel?
$urls = array('[link]', '[link]', '[link]');
$articles = array();
include_once('simple_html_dom.php');
foreach ($urls as $url) {
$html = file_get_html($url);
// Find all article blocks
foreach($html->find('div#uvod_cont') as $article) {
$item['title'] = $article->find('h1', 0)->plaintext;
$item['intro'] = $article->find('h2', 0)->plaintext;
$item['details'] = $article->find('iframe')->plaintext;
$articles[] = $item;
}
}
var_dump($articles); (odpovědět) | pcdrm | 46.231.77.* | 22.2.2015 14:00 |
|
|
|
re: PHP simple parsing HTML DOM | # |
| Klidne klasicky pouzij
for cyklus na prochazeni pole adres
$POLE_ADRES[0]="www.1.sk";
$POLE_ADRES[1]="www.2.sk";
$pocet=count($POLE_ADRES);
for ($p=0; $p<$pocet; $p++)
{
$html = file_get_html($POLE_ADRES[$p]);
$articles = array();
// Find all article blocks
foreach($html->find('div#uvod_cont') as $article) {
$item['title'] = $article->find('h1', 0)->plaintext;
$item['intro'] = $article->find('h2', 0)->plaintext;
$item['details'] = $article->find('iframe')->plaintext;
$articles[] = $item;
}
}
....
jestli sem teda spravne pochopil co potrebujes :) (odpovědět) | Aoj | 79.110.36.* | 22.2.2015 22:27 |
|
|
|