Answer the question
In order to leave comments, you need to log in
Parsing more than 1 page?
Hello.
Is there a way to scrape more than 1 page of photos on imgur?
Also the code:
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()
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