Здравствуйте.
Есть ли способ парсить более 1-ой страницы фото на сайте imgur?
Так-же код:
from bs4 import BeautifulSoup as bs
import requests
def save():
with open('C:/konosuba_par.txt', 'a') as file:
file.write(f'>Link: {comp["image"]}\n')
def parse():
URL = 'https://imgur.com/search/score?q=konosuba'
HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41'}
responce = requests.get(URL, headers = HEADERS)
soup = bs(responce.content, 'html.parser')
items = soup.findAll('div', class_ = 'post')
comps = []
for item in items:
comps.append({
'post': item.find('a', class_ = 'image-list-link').get_text(strip = True),
'image': item.find('img').get('src')
})
global comp
for comp in comps:
print(f'Link: {comp["image"]}\n')
save()
parse()