Python Forum
Downloading images from webpages
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Downloading images from webpages
#3
The site use JavaScript when click on link to generate source link to image.
Could use Selenium for this,and other way is to look as source code to see what's going on.
Can give a quick demo as this may be not a so easy if new to this.
In source download soup are all id's in a JavaScript array,can use regex to grab all id's.
Then do new call with new url that take id as parameter.
import requests
from bs4 import BeautifulSoup
import re

url = 'http://g2w.ubi.com/farcry2/?page=1'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
# Get all id's for page 1
tumb_id = re.findall(r"id=(.*)';", str(soup), re.MULTILINE)
# First one
params = (('id', tumb_id[0]),)
# Download
response = requests.get('http://g2w.ubi.com/farcry2/thumb.php', params=params)
with open('tumb.png', 'wb') as f:
    f.write(response.content)
Pedroski55 likes this post
Reply


Messages In This Thread
Downloading images from webpages - by H84Gabor - Sep-29-2021, 10:32 AM
RE: Downloading images from webpages - by Larz60+ - Sep-29-2021, 03:01 PM
RE: Downloading images from webpages - by snippsat - Sep-29-2021, 05:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to to extract urls across multple webpages at once? ilovewacha 2 283 Jun-18-2024, 06:04 PM
Last Post: snippsat
  Downloading a module Xlsxwriter dan789 6 11,648 Jan-26-2019, 02:13 PM
Last Post: dan789
  "if statement" and downloading a dataset Alberto 1 2,601 Jan-25-2018, 01:44 PM
Last Post: ka06059
  Downloading and using pyperclip PMPythonlearner 2 5,217 Dec-31-2017, 04:37 PM
Last Post: PMPythonlearner
  Problem downloading 2.7.8 Mac OSX Benjipincus 2 3,183 Dec-18-2017, 01:33 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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