[英]ValueError: unknown url type: ' ' (selenium)
我准備從服裝網站下載圖片用於學術研究,我使用下面的代碼`
from ast import keyword
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
import time
import os
import wget
import random
import time
delay_choices = range(5,15)
delay = random.choice(delay_choices)
import requests
from fake_useragent import UserAgent
keyword = "jeans"
user_agent = UserAgent()
response = requests.get(url="https://www2.hm.com/en_asia3/ladies/shop-by-product/jeans.html", headers={ 'user-agent': user_agent.random })
driver = webdriver.Chrome("~~~~")
driver.get("https://www2.hm.com/en_asia3/ladies/shop-by-product/jeans.html")
time.sleep(4)
cookie = driver.find_element(By.ID, 'onetrust-accept-btn-handler')
cookie.click()
time.sleep(2)
for i in range(6):
driver.execute_script("window.scrollTo(0, 6900);")
time.sleep(delay)
loadmore = driver.find_element(By.XPATH,"/html/body/main/div/div/div/div[3]/div[2]/button")
loadmore.click()
imgs = driver.find_elements(By.CLASS_NAME, 'item-image')
path = os.path.join("H&M" + keyword)
os.mkdir(path)
count = 0
for img in imgs:
save_as = os.path.join(path, keyword + str(count) + '.jpg')
#print(img.get_attribute("src"))
wget.download(img.get_attribute("src"), save_as)
count += 1
time.sleep(6)
driver.quit()
`
我遇到了這個問題: 在這一行中: wget.download(img.get_attribute('src'), save_as)
但是我也用“src”去下載其他網站,也沒出錯。
我想知道是否有人知道發生了什么。
非常感謝。
這個問題我已經搜索過了,沒能解決,希望有人能給我一些建議。
您嘗試使用wget
下載的 url 有很多特定符號,這可能會導致wget
出現問題。 這是您嘗試下載的 URL 的示例: https://lp2.hm.com/hmgoepprod?set=source[/2b/bf/2bbf11a29fde773adcdOK],res[y],hmver[1]&call=url [文件:/產品/主要]
嘗試稍微更改命令:
而不是這個:
wget.download(img.get_attribute("src"), save_as)
嘗試這個:
wget.download(f'"{img.get_attribute("src")}"', save_as)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.