testxmlhtml.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>GitHub Links Scraper</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. margin: 20px;
  11. }
  12. h1 {
  13. font-size: 24px;
  14. margin-bottom: 10px;
  15. }
  16. h2 {
  17. font-size: 20px;
  18. margin-top: 20px;
  19. margin-bottom: 10px;
  20. }
  21. button {
  22. padding: 10px 15px;
  23. font-size: 16px;
  24. cursor: pointer;
  25. }
  26. input {
  27. padding: 10px;
  28. font-size: 16px;
  29. margin-right: 10px;
  30. width: 300px;
  31. }
  32. #status, #content {
  33. margin-top: 20px;
  34. }
  35. #status div, #content div {
  36. margin-bottom: 15px;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <h1>GitHub Links Scraper</h1>
  42. <h2>Test Button</h2>
  43. <button id="testButton">Test Button</button>
  44. <div id="testContent"></div>
  45. <h2>Load GitHub Content</h2>
  46. <button id="loadContentButton">Load Content</button>
  47. <div id="status"></div>
  48. <div id="content"></div>
  49. <script>
  50. const githubUrl = '/cgi-bin/testcgicgi.out';
  51. const targetSelector = 'h4 a[href], li a[href]';
  52. // Function to update the status
  53. function updateStatus(message) {
  54. const statusDiv = document.getElementById('status');
  55. const statusMessage = document.createElement('p');
  56. statusMessage.textContent = message;
  57. statusDiv.appendChild(statusMessage);
  58. }
  59. // Function to fetch and display the GitHub content
  60. function displayGitHubContent() {
  61. updateStatus('Fetching content...');
  62. const xhr = new XMLHttpRequest();
  63. xhr.open('GET', githubUrl, true);
  64. xhr.onreadystatechange = function() {
  65. if (xhr.readyState === XMLHttpRequest.DONE) {
  66. if (xhr.status === 200) {
  67. // Create a new DOM parser to parse the fetched HTML
  68. const parser = new DOMParser();
  69. const doc = parser.parseFromString(xhr.responseText, 'text/html');
  70. // Get all the targeted links
  71. const links = doc.querySelectorAll(targetSelector);
  72. if (links.length > 0) {
  73. let contentHtml = '<h3>Scraped Links:</h3>';
  74. links.forEach(link => {
  75. const title = link.textContent.trim();
  76. const href = link.getAttribute('href'); // Get the raw href attribute
  77. contentHtml += `<p>Title: ${title}<br>Description (Link): <a href="${href}" target="_blank">${href}</a></p>`;
  78. });
  79. const contentDiv = document.getElementById('content');
  80. contentDiv.innerHTML = contentHtml;
  81. updateStatus('Content loaded successfully.');
  82. } else {
  83. updateStatus('No links found.');
  84. }
  85. } else {
  86. updateStatus('Failed to load content.');
  87. }
  88. updateStatus('Operation completed.');
  89. }
  90. };
  91. xhr.send();
  92. }
  93. // Function to display a test message
  94. function displayTestMessage() {
  95. const testContentDiv = document.getElementById('testContent');
  96. testContentDiv.innerHTML = '<p>Hello, World!</p>';
  97. }
  98. // Event listeners
  99. document.getElementById('testButton').addEventListener('click', displayTestMessage);
  100. document.getElementById('loadContentButton').addEventListener('click', displayGitHubContent);
  101. </script>
  102. </body>
  103. </html>