Answer the question
In order to leave comments, you need to log in
How to parse images from Yandex images?
Good afternoon.
I threw the following code, but even I can’t download pictures.
def SaveImageYandex(text):
URL = 'https://yandex.ru/images/search?text=' + text
headers = { 'accept':'*/*', 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',}
response = requests.get(URL, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
items = soup.findAll('div', class_='serp-item__preview')
for item in items:
href = item.find('a', class_='serp-item__link').get('href')
if href:
foto_url = 'https://yandex.ru' + href
response_sec = requests.get(foto_url, headers=headers)
soup_sec = BeautifulSoup(response_sec.content, 'html.parser')
items_sec = soup_sec.findAll('div', class_='MMImageContainer')
for item_sec in items_sec:
href_sec = item.find('img', class_='MMImage-Preview').get('src')
Answer the question
In order to leave comments, you need to log in
I have a similar problem, I'm wondering how did you end up solving it? And please tell me what you ended up doing
def get_link_img(url):
response=requests.get(url,headers={'user_agent':f'{ua}'})
soap= BeautifulSoup(response.content,"html.parser")
links=soap.find_all("img",class_="serp-item__thumb justifier__thumb")
for link in links:
link = link.get("src")
linked = "https:"+str(link)
#writing to a file
name=random.random()
p = requests.get(linked)
out = open(f"Galery\{name}.jpg", "wb")
out.write(p.content)
out.close()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question