Python Forum
os.rename Windows remove illegal char
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
os.rename Windows remove illegal char
#4
Good that you found an solution,here an other way.
Some advice,should always use Requests.
You see the yellow banner Wink
So this code is for python 3.6 and work on Windows, Python 3.6 and pip installation under Windows
import requests
from bs4 import BeautifulSoup

url = 'http://www.imdb.com/title/tt2527336/?ref_=rlm'
# Test other url
#url = 'http://www.imdb.com/title/tt5294550/?ref_=inth_ov_i'
#url = 'http://www.imdb.com/title/tt5726086/?ref_=inth_ov_tt'

url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'lxml')
image = soup.find('div', class_="poster")
image_name = image.find('img').get('alt').replace(':', '')
image_url = image.find('img').get('src')

# Download
response = requests.get(image_url)
with open(f'{image_name}.jpg', 'wb') as f:
        f.write(response.content)
Reply


Messages In This Thread
os.rename Windows remove illegal char - by fgerrata - Jan-03-2018, 02:06 PM
RE: os.rename Windows remove illegal char - by snippsat - Jan-03-2018, 04:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  expecting value: line 1 column 1 (char 0) in print (r.json)) loutsi 3 7,682 Jun-05-2020, 08:38 PM
Last Post: nuffink

Forum Jump:

User Panel Messages

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