Python 从beautifulSoup的网站链接获取特定图像
我正在尝试使用beautiful soup在网站上获得一些特定的图像:Python 从beautifulSoup的网站链接获取特定图像,python,beautifulsoup,Python,Beautifulsoup,我正在尝试使用beautiful soup在网站上获得一些特定的图像: from bs4 import BeautifulSoup import urllib.request import random url=urllib.request.urlopen("https://www.arandomlink.com") content = url.read() #We read it soup = BeautifulSoup(content) #We creat
from bs4 import BeautifulSoup
import urllib.request
import random
url=urllib.request.urlopen("https://www.arandomlink.com")
content = url.read() #We read it
soup = BeautifulSoup(content) #We create a BeautifulSoup object
#WE OBTAIN THE URL OF THE IMAGES RELATED TO THE ITEM
images = soup.findAll("img", {'class': "arandonclass"})
print(images['src'])
问题是它不工作,即使我验证了该类中存在图像,它也找不到任何图像。
我做错了什么?
我正在使用python 3和BS4
按CSS类进行搜索
搜索具有特定CSS类的标记非常有用,但是CSS属性的名称“class”在Python中是一个保留字。使用class作为关键字参数将导致语法错误。从Beauty Soup 4.1.2开始,您可以使用关键字参数类按CSS类搜索:
请给出您试图解析的真实url。和实
类
值
soup.find_all("a", class_="sister")