【发布时间】:2020-07-01 07:21:27
【问题描述】:
我正在尝试从 Google 图片中抓取图片。我的代码:
from selenium import webdriver
import time
keyword = "cats"
url = "https://www.google.com/search?q=" + keyword + "&source=lnms&tbm=isch&tbs="
driver= webdriver.Chrome()
driver.get(url)
time.sleep(5)
tags = driver.find_elements_by_xpath('//div[@id="islrg"]/div[@class="islrc"]/div/a[1]')
for tag in tags:
link = tag.get_attribute("href")
print(link)
这将只打印无。
在页面源代码中,标签没有 href ,我只能从 inspect element 看到它。我怎样才能得到这些元素的href?
【问题讨论】: