php - Scraping a table using Simple HTML Dom -
i trying scrape product table,
i need product id, quantity , price.
since site uses cookies , post form grabbing site curl. works fine. loading simple html dom $html = str_get_html($content);
i have been able load table values array, can't label them. come in 0,1,2 , can't tell what's what.
i tried using different method posted here on stackoverflow, gives me fatal error: call member function find() on non-object in
my working code isn't labeled
$content = curlscraper($urltoscrape); $html = str_get_html($content); $tds = $html->find('table',2)->find('td'); $num = null; foreach($tds $td) { $num[] = $td->plaintext; } echo '<pre>'; var_dump ($num); echo '</pre>';
the code found on stackoverflow gives me fatal error: call member function find() on non-object in
$content = curlscraper($urltoscrape); $html = str_get_html($content); foreach($html->find('tr',2) $page) { $item['sku'] = $page->find('td',0)->plaintext; $item['product'] = $page->find('td',1)->plaintext; $item['qty'] = $page->find('td',2)->plaintext; $item['description'] = $page->find('td',3)->plaintext; $item['price'] = $page->find('td',4)->plaintext; $table[] = $item; } print_r($table);
try initialize variable foreach function , use code. don't line created error?
$line = $html->find('tr',2); foreach($line $page) { //var_dump($page) //you can check array $item['sku'] = $page->find('td',0)->plaintext; $item['product'] = $page->find('td',1)->plaintext; $item['qty'] = $page->find('td',2)->plaintext; $item['description'] = $page->find('td',3)->plaintext; $item['price'] = $page->find('td',4)->plaintext; $table[] = $item; }
Comments
Post a Comment