Created
January 8, 2025 04:22
-
-
Save SYXiao2002/995d903dd078e23af72854ea46cb7efc to your computer and use it in GitHub Desktop.
清华大学云盘不能批量下载?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// XPath expression to target specific <a> elements | |
const xpath = `/html/body/div[1]/div/div[2]/div/table/tbody/tr/td[3]/a`; | |
// Use document.evaluate to find all nodes matching the XPath expression | |
let links = document.evaluate( | |
xpath, // XPath to locate <a> elements | |
document, // Search within the entire document | |
null, // No namespace resolver needed | |
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, // Return an ordered snapshot of matching nodes | |
null // No initial result context | |
); | |
// Array to store generated wget commands | |
let wgetCommands = []; | |
// Iterate through the snapshot to extract href and file name | |
for (let i = 0; i < links.snapshotLength; i++) { | |
let linkElement = links.snapshotItem(i); // Access the current <a> element | |
// Extract the href attribute (URL) of the link | |
let href = linkElement.href; | |
// Determine the file name starting point (last "/") | |
let startIndex = href.lastIndexOf('/'); | |
// Decode the portion after the last "/" as the initial file name | |
let fileName = decodeURIComponent(href.substring(startIndex)); | |
// Further refine the file name by splitting on "/" again and selecting the last part | |
fileName = fileName.split('/').pop(); | |
// Generate the wget command and add it to the array | |
wgetCommands.push(`wget -O "${fileName}" "${href + '&dl=1'}"`); | |
} | |
// Join all commands into a single line separated by "&&" and print to the console | |
console.log(wgetCommands.join(" && ")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment