Statement written earlier:
As a self-taught crawler, Xiaobai uses the crawler to climb the cloud disk link of 8000 books, and then wants to transfer all the resources written in the link to his own cloud disk, in case of resource failure one day. Originally, I wanted to find a software that could be saved in batches on the Internet, but I didn't know how many of them could be used. It would be unrealistic to save them manually. Then I thought that the talented selenium could simulate the operation of the browser, just like writing the automatically saved code. After three or four hours of hard work, we have the following results. I know that my writing is very bad, but this is really the result of my independent thinking and operation with the existing knowledge on the way of learning. After all, it solves the problems I actually encounter, which is completely in line with my original intention of self-study programming, and I am still very happy. Now I post the code to make everyone laugh. It's also for sharing if any God has similar and better tools.
from selenium import webdriver import time with open("book_url_pw.txt") as f: links = f.readlines() # Read resource link and password from file browser = webdriver.Chrome() # Instance a browser object for link in links: # ergodic url = link.split("----")[0] # with----Is the separator, the first half is the address, the second half is the password pw = link.split("----")[1] browser.get(url) # Request resource link time.sleep(2) browser.find_element_by_id("zvbpPbMk").send_keys(pw) # Input password browser.find_element_by_class_name("text").click() # Click OK time.sleep(2) if browser.page_source.find("user-name") != -1: print("Being preserved " + browser.find_element_by_xpath("//h2").text) browser.find_element_by_class_name("zbyDdwb").click() # Click file browser.find_element_by_xpath('//a[@class="g-button g-button-blue"]/span[@class="g-button-right"]/span[@class="text"]').click() # Click Save to online disk time.sleep(3) browser.find_element_by_xpath("//div[@class='dialog-footer g-clearfix']/a[2]").click() # Click OK time.sleep(2) print("Save successfully " + browser.find_element_by_xpath("//h2").text) else: print("Being preserved " + browser.find_element_by_xpath("//h2").text) browser.find_element_by_xpath("//dd[@class='CDaavKb']/a[1]").click() # Click the login button time.sleep(3) browser.find_element_by_xpath("//div[@class='tang-pass-footerBar']/p[2]").click() # Click account password login button time.sleep(3) browser.find_element_by_name("userName").send_keys("Cloud disk account") # Input account browser.find_element_by_name("password").send_keys("Cloud disk password") # Input password browser.find_element_by_id("TANGRAM__PSP_10__submit").click() # Click OK time.sleep(3) browser.find_element_by_class_name("zbyDdwb").click() # Click file browser.find_element_by_xpath('//a[@class="g-button g-button-blue"]/span[@class="g-button-right"]/span[@class="text"]').click() # Click Save to online disk time.sleep(3) browser.find_element_by_xpath("//div[@class='dialog-footer g-clearfix']/a[2]").click() # Click OK time.sleep(2) print("Save successfully " + browser.find_element_by_xpath("//h2").text)