Answer the question
In order to leave comments, you need to log in
How to create an exception in search?
Greetings, sometimes an error occurs in the code, and to be more specific, in the parser (it parses the url of a random photo from Google
)
.
import requests
from json import loads
from bs4 import BeautifulSoup
from random import choice
s = requests.session()
s.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0'})
r = s.get('https://www.google.ru/search?q=мем&tbm=isch')
soup = BeautifulSoup(r.text, "html.parser")
elems = soup.findAll(attrs={'class': 'rg_meta notranslate'})
print(loads(choice(elems).text)['ou'])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question