【发布时间】:2021-02-10 21:14:54
【问题描述】:
当我访问特定的产品页面时,我试图用 Selenium 从 Target 的网站上抓取产品 img url,但没有返回任何内容。
这是我的那部分代码:
# ADD THE IMAGE URL
j = 0
found = False
while(j < 5 and not found):
try:
img_panel = driver.find_element_by_class_name('slideDeckPicture')
img_panel = img_panel.find_element_by_tag_name('img')
img_name = img.get_attribute('alt')
img_url = img_panel.get_attribute('src')
# img_urls.append(img_url)
line += ',"' + img_url + '"'
found = True
break
# if it can't find the image, it probably hasn't loaded. wait and try again.
except:
j += 1
time.sleep(4)
# img_urls.append('NO URL')
# pass
# if we've tried 5 times add no url
if found == False:
line += ',NO IMG URL'
【问题讨论】:
标签: python web-scraping data-science