Tuesday, 15 August 2023
Friday, 11 August 2023
html code for Scan PDF links from web pages
<!DOCTYPE html>
<html>
<head>
<title>Extract PDF Links</title>
<script>
function extractPDFLinks() {
// Get the webpage link from the form.
var webpageLink = document.getElementById("webpageLink").value;
// Create an array to store the PDF links.
var pdfLinks = [];
// Get all the anchor tags on the page.
var anchorTags = document.getElementsByTagName("a");
// Loop through the anchor tags and check if they point to PDF files.
for (var i = 0; i < anchorTags.length; i++) {
var link = anchorTags[i];
// Get the link's href attribute.
var href = link.href;
// Check if the href attribute ends with .pdf.
if (href.endsWith('.pdf')) {
// Add the link to the PDF links array.
pdfLinks.push(link);
}
}
// Create a div to display the PDF links.
var div = document.createElement('div');
div.setAttribute('id', 'pdf-links');
// Loop through the PDF links and add them to the div.
for (var i = 0; i < pdfLinks.length; i++) {
var link = pdfLinks[i];
// Get the link's text.
var text = link.textContent;
// Create a span element to display the link's text.
var span = document.createElement('span');
span.textContent = text;
// Create a button element to download the link's file.
var button = document.createElement('button');
button.textContent = 'Download';
button.addEventListener('click', function() {
window.location.href = link.href;
});
// Add the span and button elements to the div.
div.appendChild(span);
div.appendChild(button);
}
// Append the div to the document body.
document.body.appendChild(div);
}
</script>
</head>
<body>
<h1>Extract PDF Links</h1>
<form>
<input type="text" id="webpageLink" placeholder="Enter the webpage link">
<button type="button" onclick="extractPDFLinks()">Extract PDF Links</button>
</form>
<div id="pdf-links"></div>
</body>
</html>