Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从beautifulSoup的网站链接获取特定图像_Python_Beautifulsoup - Fatal编程技术网

Python 从beautifulSoup的网站链接获取特定图像

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

我正在尝试使用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 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")