赞
踩
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() #关闭浏览器
# 在li标签中找a标签,再在a标签中找img标签
img = li.find_element_by_tag_name('a').find_element_by_tag_name('img')
get_attribute('href') # 获取a标签/img标签的href属性
get_attribute('innerHTML') # 获取img标签的内部text内容
print(img.get_attribute('innerHTML'))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。