目标内容(红框中的图片)
代码
from tqdm import tqdm
from selenium import webdriver
from six.moves import urllib
wd = webdriver.Chrome()
names = ['spellList']
targetUrls = ['https://lol.qq.com/data/info-spell.shtml#Navi', ]
for index, name in enumerate(names):
wd.get(targetUrls[index])
block = wd.find_element_by_id(name)
liList = block.find_elements_by_tag_name('li')
for li in tqdm(liList):
img = li.find_element_by_tag_name('img')
url = img.get_attribute('src')
urllib.request.urlretrieve(url, f'./imgs/{url.split("/")[-1]}')
wd.quit()
根据父节点找其儿子节点
img = li.find_element_by_tag_name('a').find_element_by_tag_name('img')
获取标签的指定内容
get_attribute('href')
get_attribute('innerHTML')
print(img.get_attribute('innerHTML'))
|