WP plugin scrapping tool part 13 (display scrap data using shortcode according to website and number of rows)

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.

all-shortcodes.php

<?php

function all_shortcode_fun(){
?>

<div class="table-responsive container-fluid p-3" style="margin-top:30px; background:#fff;
padding:20px">
<button class="btn btn-primary" data-toggle="modal" data-target="#addModel">Add Shortcodes</button><br/><br/>

<?php

if(isset($_POST['submit'])){
global $wpdb;

$website_url = $_POST['website_url']; 
$no_of_post_show = $_POST['no_of_post_show'];
$shortcode = $_POST['shortcode'];
$atts = 'shortcode='.$shortcode.' post_count='.$no_of_post_show;

$table_name = 'wp_scrap_shortcode';
$q = $wpdb->insert( 
$table_name, 
array( 
'website_url' => $website_url, 
'number_of_post_show' => $no_of_post_show, 
'shortcode' => $shortcode,
'atts' => $atts
)

);

if($q){
echo "<div style='padding:10px; color:white; background:green'>Data Saved</div>";
}
else{
echo "<div style='padding:10px; color:white; background:red'>Something went wrong !</div>";
}

}

?>


<!-- add website start -->

<div class="modal" id="addModel">
<div class="modal-dialog">
<div class="modal-content">

<!-- Modal Header -->
<div class="modal-header">
<h2 class="modal-title">Add New Shortcode</h2>
</div>

<!-- Modal body -->
<div class="modal-body">


<form action="admin.php?page=all-shortcodes" method="post">
<div class="form-group">
<label for="website_url">Website url:</label>
<select class="form-control" name="website_url" style="width:100%">
<option>--Choose any website--</option>
<?php 

global $wpdb;
$result = $wpdb->get_results("SELECT * FROM wp_websites");
foreach ($result as $key => $print) {
?>

<option value="<?php echo $print->website_url; ?>"><?php echo $print->website_url; ?></option>

<?php } ?> 
</select>
</div>

<div class="form-group">
<label for="selector">Number of post show in frontend:</label>
<input type="text" class="form-control" name="no_of_post_show" value="5">
</div>

<div class="form-group">
<label for="thumb">Give Any Shortcode:</label> 
<input type="text" class="form-control" name="shortcode" value="<?php echo rand(10000, 99999); ?>" 
readonly>
</div>

<button type="submit" class="btn btn-default" name="submit">Submit</button>
<button type="button" class="btn btn-dark" data-dismiss="modal">No</button>
</form>

</div>

<!-- Modal footer -->
<div class="modal-footer">

</div>

</div>
</div>
</div>

<!-- add website end -->

<table class="table table-striped p-3" style="background:#f7f7f7; padding:30px" id="datatablespk">

<thead>

<th style="text-align:center;"><center>S.No</center></th>
<th><center>Website url</center></th>
<th><center>Number of post show in frontend</center></th>
<th><center>Shortcodes</center></th>
<th><center>Action</center></th>

</thead>


<!-- loop start -->

<?php 

$result = $wpdb->get_results("SELECT * FROM wp_scrap_shortcode");
foreach ($result as $key => $print) {
?>

<tr>
<td width='5%'><center><?php echo $key+1; ?></center></td>
<td width='25%'><center><?php echo $print->website_url; ?></center></td>
<td width='15%'><center><?php echo $print->number_of_post_show; ?></center></td>
<td width='15%'><center>[<?php echo $print->shortcode.' '.$print->atts; ?>]</center></td>
<td width='20%'>
<center>
<button class='btn btn-danger btn-sm' type='button' data-toggle="modal" data-target="#myModal<?php echo $print->id; ?>">DELETE</button>
</center>
</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">
<h2 class="modal-title">Data Delete</h2>
</div>

<!-- Modal body -->
<div class="modal-body">
Are You want to delete this <b style="color:green"><u><?php echo $print->website_url; ?></u></b> website ?.
</div>

<!-- Modal footer -->
<div class="modal-footer">
<a href="admin.php?page=delete-shortcode&del=<?php echo $print->id; ?>">
<button type="button" class="btn btn-danger">Yes</button>
</a>
<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;
}

div.dt-container select.dt-input {
padding: 4px;
width: 65px;
margin-right: 10px;
}

</style>

<?php 
}

all_shortcode_fun();

?>
delete-shortcode.php

<?php

global $wpdb;

if (isset($_GET['del'])) { 
$del_id = $_GET['del'];
$wpdb->query("DELETE FROM wp_scrap_shortcode WHERE id='$del_id'");

echo "<script>location.replace('admin.php?page=all-shortcodes');</script>";
}

?>
all-shortcodes-website-list.php

<?php

function all_shortcode_created_list_fun(){
?>

<!-- loop start -->

<?php


function all_shortcode_created_list_fun2($shortcode){
add_shortcode($shortcode, 'all_shortcode_created_list_fetch_fun');
}

function all_shortcode_created_list_fetch_fun($atts){
$shortcode_ar = shortcode_atts([
'shortcode' => 'abc.com',
'post_count' => 1,
], $atts
);

$sc = $shortcode_ar['shortcode'];
$count = $shortcode_ar['post_count'];

global $wpdb; 
$result_sc = $wpdb->get_results("SELECT * FROM wp_scrap_shortcode WHERE shortcode=$sc");

foreach ($result_sc as $key => $print_sc) {
$url = $print_sc->website_url;

$result_sc2 = $wpdb->get_results("SELECT * FROM wp_scrap WHERE website_url='$url' LIMIT $count");

foreach ($result_sc2 as $key => $print_sc2) {
$website_url = $print_sc2->website_url;
$details_page_url = $print_sc2->url;
$title = $print_sc2->title;
$thumb = $print_sc2->thumb;
echo $title."<br/>";
}

}

}

global $wpdb; 
$result = $wpdb->get_results("SELECT * FROM wp_scrap_shortcode");

foreach ($result as $key => $print) {
$shortcode = $print->shortcode;
all_shortcode_created_list_fun2($shortcode);

}
// loop end


?>

</div>

<style>

</style>


<?php 
}

all_shortcode_created_list_fun();

?>

 

 

 

 

Leave a Reply