# The urllib library, used to retrieve the content of webpages
# also contains functions to retrieve the content of files
from urllib.request import urlretrieve
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen('http://www.pythonscraping.com')
bs = BeautifulSoup(html, 'html.parser')
imageLocation = bs.find('a', {'id':'logo'}).find('img')['src']
urlretrieve(imageLocation, 'logo.jpg')

#run
#python cp6_p112.py

# This works well if you need to download only a single file
# and know what to call it and what the file extension is.

cp6_p113_Download A Single File

相关文章:

  • 2021-12-22
  • 2021-12-03
  • 2021-11-17
  • 2021-09-07
  • 2021-12-09
  • 2021-11-14
  • 2021-10-22
猜你喜欢
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-10-17
  • 2021-08-25
  • 2022-12-23
相关资源
相似解决方案