Web Scraping is a technique used to extract large amounts of data from websites extracted and saved them to a local file in your computer or to a database or can be used as API. Data displayed by most websites can be viewed by using a web browser only. They do not offer the functionality to save a copy of this data for use. Thus the only option is to copy and paste the selected data that is required, which in reality, is a very tedious job and may take hours complete. In other terms, Web Scraping is the technique of automating such a process, in place of manual work, the Web Scraping software performs the same task within seconds.
menu.php
add_submenu_page('all-websites', __('All Srapped Data',
'all-data'), __('All Srapped Data', 'all-data'),
'manage_options', 'all-data',
'all_scrapped_data_function');
function all_scrapped_data_function(){
require_once __DIR__ . "/scrapping-form/scrap-data.php";
}
add_submenu_page('', __('',
'delete-scrap-website'), __('', 'delete-scrap-website'),
'manage_options', 'delete-scrap-website',
'delete__scrap_websites_function');
function delete__scrap_websites_function(){
require_once __DIR__ . "/scrapping-form/delete-scrap-data.php";
}
scrap-data.php
<div class="table-responsive container-fluid p-3" style="margin-top:30px;">
<table class="table table-stripped p-3" style="background:#f7f7f7; padding:30px" id="datatablespk">
<thead>
<th style="text-align:center;">S.No</th>
<th>Website url</th>
<th>Heading</th>
<th>Thumbnail</th>
<th>Details Page url</th>
<th>Action</th>
</thead>
<!-- loop start -->
<?php
global $wpdb;
$result = $wpdb->get_results("SELECT * FROM wp_scrap");
foreach ($result as $key => $print) {
?>
<tr>
<td width='5%'><?php echo $key+1; ?></td>
<td width='25%'><?php echo $print->website_url; ?></td>
<td width='15%'><?php echo $print->title; ?></td>
<td width='15%'><img src="<?php echo $print->thumb; ?>" width="100px" height="40px"></td>
<td width='15%'><a href="<?php echo $print->url; ?>" class="btn btn-primary btn-sm">Click Here</a></td>
<td width='20%'>
<button class='btn btn-danger btn-sm' type='button' data-toggle="modal" data-target="#myModal<?php echo $print->id; ?>">DELETE</button>
</td>
</tr>
<!-- The Modal -->
<div class="modal" id="myModal<?php echo $print->id; ?>">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Data Delete</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
Are You sure ? to want delete this <?php echo $print->website_url; ?> item.
</div>
<!-- Modal footer -->
<div class="modal-footer">
<a href="admin.php?page=delete-scrap-website&del=<?php echo $print->id; ?>">
<button type="button" class="btn btn-danger">Yes</button>
</a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-dark" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
<?php
}
?>
<!-- loop end -->
</table>
</div>
<script>
$(document).ready(function() {
$('#datatablespk').dataTable({
"scrollX": false,
"pagingType": "numbers"
} );
} );
</script>
<style>
td, thead>th {
text-align:left;
}
</style>
delete-scrap-data.php
<?php
global $wpdb;
if (isset($_GET['del'])) {
$del_id = $_GET['del'];
$wpdb->query("DELETE FROM wp_scrap WHERE id='$del_id'");
echo "<script>location.replace('admin.php?page=all-data');</script>";
}
?>