Python Forum
HTTPError: Forbidden when try download image
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTTPError: Forbidden when try download image
#5
They are blocking urllib,but it work with Requests(as you should use anyway).
Quote:please write it for me , i cant understand anything
You should try yourself,but to be nice here how to download 1 image.
You always do test like this,before you are making a loop Undecided
from bs4 import BeautifulSoup
import requests
import os

page = 4
url = 'https://alpha.wallhaven.cc/random?page={}'.format(page)
url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'html.parser')
# Parse
kelimeler = soup.find("img", {"class":"lazyload"})
img_nr = os.path.basename(kelimeler['data-src'])
img_nr = img_nr.split('-')[-1]
img_large = 'https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-{}'.format(img_nr)
# Download
down_link = requests.get(img_large)
with open(img_nr, "wb") as img_obj:
    img_obj.write(down_link.content)
Reply


Messages In This Thread
RE: HTTPError: Forbidden when try download image - by snippsat - Jan-20-2017, 11:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  403 Forbidden Error Evil_Patrick 1 4,488 Jun-20-2020, 02:19 PM
Last Post: snippsat
  urllib.error.HTTPError: HTTP Error 404: Not Found ckkkkk 4 8,830 Mar-03-2020, 11:30 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020