TA的每日心情 无聊 4 天前
签到天数: 530 天
连续签到: 2 天
[LV.9]测试副司令
1 测试积点
# _*_coding:utf-8_*_
# ! python 3.8
# This is the code for selenium to get the comixes.
"""
# Author_by uFTvL9
# the first page of the ComiX is
https://xmanhua.com/m11156/
"""
# import_list
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import requests
import os
import random
def init():
print("-" * 70)
print("\t\tPlease imput your target comix URL")
# url = input()
url = 'https://xmanhua.com/m11156/'
print("Webdriver is opening your website. Please wait...")
return url
def get_page(driver, url):
# Download the page
driver.get(str(url))
print("Implicitly waiting...")
driver.implicitly_wait(10)
print("WebDriver waiting...")
WebDriverWait(driver, 25)
# driver.maximize_window() # maximize the window(full screen)
html = driver.page_source
print(html)
return html
def search(driver, char, element):
# Find the URL of the comic image.
if char == '#':
driver.implicitly_wait(5)
Image_element = driver.find_element(By.ID, str(element))
Image_element.get_attribute('src')
return Image_element
def download_image(comicUrl):
# Download the image
print('Downloading image...')
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0'}
proxy = [{'http': 'http://180.110.212.36:8118'}, {'http': 'http://122.246.49.135:8010'},
{'http': 'http://111.155.116.245:8123'}, {'http': 'http://123.56.169.22:3128'}]
proxies = random.choice(proxy)
folder_name = "To you who will not perish"
print(proxies)
try:
imgFile = requests.get(comicUrl, headers=headers, proxies=proxies)
if imgFile.status_code == 200 or imgFile.status_code == 304:
imageFile = open(os.path.join(folder_name, os.path.basename(image_name)), 'wb')
for chunk in res.iter_content(100000):
imageFile.write(chunk)
imageFile.close()
except Exception as exc:
print('There was a problem %s' % exc)
'''
def get_PrevLink(soup, varstr):
# Get the button's url.
'''
def main():
url = 'https://xmanhua.com/m11156/'
driver = webdriver.Firefox()
get_page(driver, url)
Image_url = search(driver, "#", "cp_image")
download_image(str(Image_url))
driver.quit()
print('Done')
if __name__ == "__main__":
main() 复制代码 出现错误
There was a problem Invalid URL '<selenium.webdriver.remote.webelement.WebElement (session="88990c6b-f1ea-413d-9ab6-101e03161420", element="e17b5c1a-1739-49ea-b4d1-d7c10ac994eb")>': No scheme supplied. Perhaps you meant http://<selenium.webdriver.remote.webelement.WebElement (session="88990c6b-f1ea-413d-9ab6-101e03161420", element="e17b5c1a-1739-49ea-b4d1-d7c10ac994eb")>?
Done
复制代码 如何解决?
我来回答