Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $main_link = "https://www.viewvillage.in/district/ahmadabad-438"; $subDistId = 1; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/amreli-439"; $subDistId = 18; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/anand-440"; $subDistId = 29; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/arvalli-672"; $subDistId = 38; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/banas-kantha-441"; $subDistId = 44; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/bharuch-442"; $subDistId = 58; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/bhavnagar-443"; $subDistId = 67; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/botad-676"; $subDistId = 77; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/chhotaudepur-668"; $subDistId = 81; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/dohad-445"; $subDistId = 87; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/dang-444"; $subDistId = 96; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/devbhumi-dwarka-674"; $subDistId = 99; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/gandhinagar-446"; $subDistId = 103; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/gir-somnath-675"; $subDistId = 107; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/jamnagar-447"; $subDistId = 113; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/junagadh-448"; $subDistId = 120; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/kachchh-449"; $subDistId = 130; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/kheda-450"; $subDistId = 140; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/mahisagar-669"; $subDistId = 151; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/mahesana-451"; $subDistId = 157; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/morbi-673"; $subDistId = 167; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/narmada-452"; $subDistId = 172; // Starting sub-district ID :: Please Check Database Have 7 Sub District And in Link 5 Sub Dist
- // $main_link = "https://www.viewvillage.in/district/navsari-453"; $subDistId = 179; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/panch-mahals-454"; $subDistId = 185; // Starting sub-district ID :: Please Check Database Have 8 Sub District And in Link 7 Sub Dist
- // $main_link = "https://www.viewvillage.in/district/patan-455"; $subDistId = 193; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/porbandar-456"; $subDistId = 202; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/rajkot-457"; $subDistId = 205; // Starting sub-district ID
- // $main_link = "https://www.viewvillage.in/district/sabar-kantha-458"; $subDistId = 219; // Starting sub-district ID :: Please Check Database Have 9 Sub District And in Link 8 Sub Dist
- // $main_link = "https://www.viewvillage.in/district/surat-459"; $subDistId = 228; // Starting sub-district ID :: Please Check Database Have 15 Sub District And in Link 14 Sub Dist
- // $main_link = "https://www.viewvillage.in/district/surendranagar-460"; $subDistId = 243; // Starting sub-district ID :: Please Check Database Have 11 Sub District And in Link 10 Sub Dist
- // $main_link = "https://www.viewvillage.in/district/tapi-641"; $subDistId = 254; // Starting sub-district ID :: Please Check Database Have 8 Sub District And in Link 7 Sub Dist
- // $main_link = "https://www.viewvillage.in/district/vadodara-461"; $subDistId = 262;
- $main_link = "https://www.viewvillage.in/district/valsad-462"; $subDistId = 274;
- // Fetch the content of the main link
- $response = @file_get_contents($main_link);
- if ($response === FALSE) {
- echo "Error fetching data from: $main_link\n";
- exit; // Exit if there is an error
- }
- // Create a DOM parser for the main link
- $dom = new DOMDocument();
- @$dom->loadHTML($response); // Suppress warnings due to invalid HTML
- // Use XPath to extract village list links
- $xpath = new DOMXPath($dom);
- $villageNodes = $xpath->query('//tbody/tr/td[2]/a[@href]'); // Adjust the selector to find the links
- $villageLinks = []; // Array to hold the village links
- foreach ($villageNodes as $node) {
- $villageLinks[] = $node->getAttribute('href'); // Get the village link
- }
- foreach ($villageLinks as $link) {
- // Fetch the content of the village list page
- $response = @file_get_contents($link);
- if ($response === FALSE) {
- echo "Error fetching data from: $link\n";
- continue; // Skip this link if there is an error
- }
- // Create a DOM parser for the village link
- $dom = new DOMDocument();
- @$dom->loadHTML($response); // Suppress warnings due to invalid HTML
- // Use XPath to extract village names
- $xpath = new DOMXPath($dom);
- $villageNodes = $xpath->query('//td'); // Adjust this selector as needed
- // Check if village names were found
- if ($villageNodes->length === 0) {
- echo "No village names found for: $link\n";
- continue; // Skip this link if no village names are found
- }
- $values = []; // Initialize an array to hold values for the current link
- foreach ($villageNodes as $node) {
- // Only take the second <td> (the village name)
- if ($node->parentNode->childNodes->length > 1) {
- $villageName = trim($node->textContent); // Get the village name
- // Prepare the value for insertion
- $values[] = "(NULL, '$subDistId', '$villageName', NULL, NULL, 'active', '0', '0', current_timestamp(), NULL)";
- }
- }
- // Create the SQL query for the current link if there are values
- if (!empty($values)) {
- $sqlQueries = "INSERT INTO `tbl_village` (`village_id`, `sub_dist_id`, `village_name`, `village_name_guj`, `village_name_hin`, `status`, `created_by`, `updated_by`, `created_at`, `updated_at`) VALUES\n" . implode(",\n", $values) . ";\n";
- echo "<pre>$sqlQueries</pre><br>"; // Output the SQL query
- } else {
- echo "No village names found for: $link\n";
- }
- $subDistId++; // Increment sub-district ID for the next link
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement