我对python和所有东西都是新手,我希望在一个div类中解析所有href。我的目标是创建一个程序来打开div类中的所有链接,以便能够保存与href关联的照片
链接:https://www.opi.com/shop-products/nail-polish-powders/nail-lacquer
我要分析的部分是“div id:all\u nail\u漆器”
到目前为止,我能够获得所有的href,这就是我目前所拥有的:
import urllib
import urllib.request
from bs4 import BeautifulSoup
theurl = "https://www.opi.com/shop-products/nail-polish-powders/nail-lacquer"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage, "html.parser")
print(soup.title.text)
nail_lacquer = (soup.find('div', {"id":"all_nail_lacquer"}))
"""
for nail_lacquer in soup.find_all('div'):
print(nail_lacquer.findAll('a')
"""
for a in soup.findAll('div', {"id":"all_nail_lacquer"}):
for b in a.findAll('a'):
print(b.get('href'))
要打印图像链接(甚至高分辨率图像)和标题,可以使用以下脚本:
印刷品:
编辑:要将图像保存到磁盘,可以使用以下脚本:
相关问题 更多 >
编程相关推荐