Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium从url中抓取缺少的图像_Python_Selenium_Selenium Webdriver_Web Scraping - Fatal编程技术网

Python Selenium从url中抓取缺少的图像

Python Selenium从url中抓取缺少的图像,python,selenium,selenium-webdriver,web-scraping,Python,Selenium,Selenium Webdriver,Web Scraping,你好,我所有的任务都是从提供链接中删除源URL 但是当我尝试获取这样的元素时(请注意,我对url发出了两个请求以获取cookies,因为第一次是将我重定向到主页): 没有找到任何元素,当我尝试在浏览器的源代码中使用Ctrl+U搜索它们时,它们丢失了。为什么会这样?任何人都可以告诉我如何获取这些图像。您只需告诉selenium耐心等待即可: 出于演示目的,它打印图像的alt属性,即: Joe Boxer Men's Pajama Shirt & Pants - Plaid 或者您可以通过

你好,我所有的任务都是从提供链接中删除源URL

但是当我尝试获取这样的元素时(请注意,我对url发出了两个请求以获取cookies,因为第一次是将我重定向到主页):


没有找到任何元素,当我尝试在浏览器的源代码中使用Ctrl+U搜索它们时,它们丢失了。为什么会这样?任何人都可以告诉我如何获取这些图像。

您只需告诉selenium耐心等待即可:

出于演示目的,它打印图像的
alt
属性,即:

Joe Boxer Men's Pajama Shirt & Pants - Plaid

或者您可以通过xpath查找,然后获取图像url

>>> driver.get('http://www.kmart.com/joe-boxer-men-s-pajama-shirt-pants-plaid/p-046VA92629712P')
>>> s = driver.find_element_by_xpath('//*[@id="overview"]/div[1]/img')
>>> s.get_attribute('src') 
'http://c.shld.net/rpx/i/s/i/spin/-122/prod_2253990712?hei=624&wid=624&op_sharpen=1'

哦,我的上帝,你是我的救世主!谢谢,我不知道有等待元素的函数。圣诞快乐!
Joe Boxer Men's Pajama Shirt & Pants - Plaid
>>> driver.get('http://www.kmart.com/joe-boxer-men-s-pajama-shirt-pants-plaid/p-046VA92629712P')
>>> s = driver.find_element_by_xpath('//*[@id="overview"]/div[1]/img')
>>> s.get_attribute('src') 
'http://c.shld.net/rpx/i/s/i/spin/-122/prod_2253990712?hei=624&wid=624&op_sharpen=1'