Chrome Python Selenium与Google -如何提取图像

wvmv3b1j  于 11个月前  发布在  Go
关注(0)|答案(2)|浏览(114)

我试图提取所有的图像从一个OfferUp搜索 selenium ,但我已经尝试了一堆不同的代码,没有工作.我希望能够显示在另一个网站或弹出窗口中的所有图像,这样我就可以有一个更新的价格上OfferUp项目.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

# Driver path
chrome_driver_path = 'C:\\Users\gues\\OneDrive\\Desktop\\PyFiles\\chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.maximize_window()

# Open webpage
wait = WebDriverWait(driver, 20)
openOfferUp = driver.get('https://offerup.com/search?q=dresser&DISTANCE=20&DELIVERY_FLAGS=p&PRICE_MAX=100')

#retrieve images
time.sleep(20)
images = driver.find_elements((By.TAG_NAME, 'img'))
image_urls = [image.get_attribute('src') for image in images]
for url in image_urls:
    print(url)

time.sleep(1000)

字符串

omqzjyyz

omqzjyyz1#

试试这个:

images = driver.find_elements(By.TAG_NAME, 'img')

字符串

kh212irz

kh212irz2#

你可以试试这个:

img_urls = [img_element.get_attribute("src") for img_element in driver.find_elements(By.XPATH, {img_xpath})]

字符串

相关问题