# searchpro/1.9.7/simplehtmldom/example/scraping/example_scraping_general.php

BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS &amp; JavaScript, version 1.9.7. 59 lines.

- Page: https://pluginprobe.com/plugins/searchpro/1.9.7/code/simplehtmldom/example/scraping/example_scraping_general.php
- Raw: https://pluginprobe.com/plugins/searchpro/1.9.7/raw/simplehtmldom/example/scraping/example_scraping_general.php
- Modified: 2024-08-20T18:00:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/searchpro/1.9.7/code/simplehtmldom/example/scraping/example_scraping_general.php#L10-L20`.

```php
<?php
include_once('simple_html_dom.php');

function scraping_generic($url, $search) {
	// Didn't find it yet.
	$return = false;

	echo "reading the url: " . $url . "<br/>";
    // create HTML DOM
    $html = file_get_html($url);
	echo "url has been read.<br/>";

    // get article block
    foreach($html->find($search) as $found) {
		// Found at least one.
		$return - true;
		echo "found a: " . $search . "<br/><pre>";
		$found->dump();
		echo "</pre><br/>";
    }
    
    // clean up memory
    $html->clear();
    unset($html);

    return $return;
}


// ------------------------------------------
error_log ("post:" . print_r($_POST, true));
$url = "";
if (isset($_POST['url']))
{
	$url = $_POST['url'];
}
$search = "";
if (isset($_POST['search']))
{
	$search = $_POST['search'];
}
?>
<form method="post">
	URL: <input name="url" type="text" value="<?=$url;?>"/><br/>
	Search: <input name="search" type="text" value="<?=$search;?>"/>
	<input name="submit" type="submit" value="Submit"/>
</form>
<?php
// -----------------------------------------------------------------------------
// test it!
if (isset ($_POST['submit']))
{
	$response = scraping_generic($_POST['url'], $_POST['search']);
	if (!$response)
	{
		echo "Did not find any: " . $_POST['search'] . "<br />";
	}
}
?>
```
