Bilder einer Website herunterladen

Gute Links und Tutorials könnt ihr hier posten.
Antworten
DeadBarney
User
Beiträge: 4
Registriert: Sonntag 7. Oktober 2018, 13:54

Moin, ich stehe vor folgender Aufgabe.
Auf der Internetseite https://apod.nasa.gov/apod/archivepix.html sind mehrere Bilder hinterlegt, die ich runterladen möchte und als Bildschirmhintergrund verwenden möchte. Da ich Pythonneuling bin, bräuchte ich ein paar Ideen und Ansätze, wie ich diese am einfachsten tun kann.
LG DB
Benutzeravatar
sls
User
Beiträge: 480
Registriert: Mittwoch 13. Mai 2015, 23:52
Wohnort: Country country = new Zealand();

Eine Idee wäre, das urllib-Modul zu verwenden. Auch requests ist gut. Ein Ansatz wäre, die jeweilige Doku zu lesen, und sich bei Verständnisproblemen oder fehlgeschlagenen Versuchen wieder hier zu melden.
When we say computer, we mean the electronic computer.
Benutzeravatar
__blackjack__
User
Beiträge: 12984
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

Dann bräuchte man noch einen HTML-Parser, bzw. eine Bibliothek um das HTML nach Links und Bildern absuchen zu können. Hier ist BeautifulSoup recht beliebt.
“Most people find the concept of programming obvious, but the doing impossible.” — Alan J. Perlis
DeadBarney
User
Beiträge: 4
Registriert: Sonntag 7. Oktober 2018, 13:54

Habe es mit request versucht, worauf die Meldung kam
wollte erst probieren, ob es eine normale seite aufruft

Code: Alles auswählen

#coding= UTF-8
import urllib.request

x = urllib.request.urlopen('https://www.google.com/')
print(x.read())
ImportError: No module named request
habe es nach dieser website runtergeladen: https://stackoverflow.com/questions/173 ... d-requests

kann es sein, dass es nicht funktioniert, weil ich Ubuntu verwende?
Benutzeravatar
__blackjack__
User
Beiträge: 12984
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@DeadBarney: Schau mal welche Python-Version Du verwendest und dann in der dazu passenden Dokumentation welche Module es da unter welchen Namen bzw. in welchen Packages in der Standardbibliothek gibt.

Ich persönlich würde ja das externe `requests`-Modul für so etwas verwenden.
“Most people find the concept of programming obvious, but the doing impossible.” — Alan J. Perlis
DeadBarney
User
Beiträge: 4
Registriert: Sonntag 7. Oktober 2018, 13:54

Code: Alles auswählen

 python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Code: Alles auswählen

help> modules

Code: Alles auswählen

BaseHTTPServer      atexit              hashlib             rexec
Bastion             atk                 heapq               rfc822
CDROM               attr                hmac                rlcompleter
CGIHTTPServer       audiodev            hotshot             robotparser
Canvas              audioop             html5lib            runpy
ConfigParser        base64              htmlentitydefs      samba
Cookie              bdb                 htmllib             sched
Crypto              binascii            httplib             select
DLFCN               binhex              httplib2            serial
Dialog              bisect              idna                service_identity
DocXMLRPCServer     blinker             ihooks              sets
FileDialog          bonobo              imaplib             setuptools
FixTk               bs4                 imghdr              sgmllib
HTMLParser          bsddb               imp                 sha
IN                  bz2                 importlib           shelve
MimeWriter          cPickle             imputil             shlex
ORBit               cProfile            indicator_keyboard  shutil
OpenSSL             cStringIO           inspect             signal
PAM                 cairo               io                  site
PIL                 calendar            ipaddress           sitecustomize
Queue               caribou             itertools           six
ScrolledText        ccm                 json                smtpd
SimpleDialog        certifi             jwt                 smtplib
SimpleHTTPServer    cgi                 keyword             sndhdr
SimpleXMLRPCServer  cgitb               ldb                 socket
SocketServer        chardet             lib2to3             softwarecenter_aptd_plugins
StringIO            chunk               linecache           spwd
TYPES               cmath               linuxaudiodev       sqlite3
Tix                 cmd                 locale              sre
Tkconstants         code                lockfile            sre_compile
Tkdnd               codecs              logging             sre_constants
Tkinter             codeop              lsb_release         sre_parse
UserDict            collections         lxml                ssl
UserList            colorsys            macpath             stat
UserString          commands            macurl2path         statvfs
_LWPCookieJar       compileall          mailbox             string
_MozillaCookieJar   compiler            mailcap             stringold
__builtin__         compizconfig        markupbase          stringprep
__future__          contextlib          marshal             strop
_abcoll             cookielib           math                struct
_ast                copy                md5                 subprocess
_bisect             copy_reg            mhlib               sunau
_bsddb              crypt               mimetools           sunaudio
_cffi_backend       cryptography        mimetypes           symbol
_codecs             csv                 mimify              symtable
_codecs_cn          ctypes              mmap                sys
_codecs_hk          cups                modulefinder        sysconfig
_codecs_iso2022     curses              multifile           syslog
_codecs_jp          datetime            multiprocessing     tabnanny
_codecs_kr          dbhash              mutex               talloc
_codecs_tw          dbm                 ndg                 tarfile
_collections        dbus                netrc               tdb
_csv                deb822              new                 telnetlib
_ctypes             debconf             nis                 tempfile
_ctypes_test        debian              nntplib             termios
_curses             debian_bundle       ntpath              test
_curses_panel       debtagshw           nturl2path          textwrap
_dbus_bindings      decimal             numbers             this
_dbus_glib_bindings defer               numpy               thread
_elementtree        difflib             oauthlib            threading
_functools          dircache            oneconf             time
_hashlib            dirspec             opcode              timeit
_heapq              dis                 operator            tkColorChooser
_hotshot            distutils           optparse            tkCommonDialog
_io                 dns                 os                  tkFileDialog
_json               doctest             os2emxpath          tkFont
_ldb_text           dsextras            ossaudiodev         tkMessageBox
_locale             dumbdbm             pango               tkSimpleDialog
_lsprof             dummy_thread        pangocairo          toaiff
_md5                dummy_threading     parser              token
_multibytecodec     duplicity           pdb                 tokenize
_multiprocessing    easy_install        pi                  trace
_osx_support        email               pickle              traceback
_pyio               encodings           pickletools         ttk
_random             ensurepip           pip                 tty
_sha                enum                pipes               turtle
_sha256             errno               piston_mini_client  twisted
_sha512             exceptions          pkg_resources       types
_socket             fcntl               pkgutil             ubuntu_sso
_sqlite3            filecmp             platform            unicodedata
_sre                fileinput           plistlib            unittest
_ssl                fnmatch             popen2              urllib
_strptime           formatter           poplib              urllib2
_struct             fpectl              posix               urllib3
_symtable           fpformat            posixfile           urlparse
_sysconfigdata      fractions           posixpath           user
_sysconfigdata_nd   ftplib              pprint              uu
_tdb_text           functools           profile             uuid
_testcapi           future_builtins     pstats              warnings
_threading_local    gc                  pty                 wave
_tkinter            gconf               pwd                 weakref
_warnings           genericpath         py_compile          webbrowser
_weakref            getopt              pyasn1              wheel
_weakrefset         getpass             pyasn1_modules      whichdb
abc                 gettext             pyatspi             wsgiref
aifc                gi                  pyclbr              xapian
antigravity         gio                 pydoc               xdg
anydbm              glib                pydoc_data          xdrlib
apt                 glob                pyexpat             xml
apt_inst            gnome               pygtk               xmllib
apt_pkg             gnomecanvas         pygtkcompat         xmlrpclib
aptdaemon           gnomevfs            quopri              xxsubtype
aptsources          gobject             random              zipfile
argparse            grp                 re                  zipimport
array               gtk                 readline            zlib
ast                 gtkunixprint        repr                zope
asynchat            gtweak              requests            
asyncore            gzip                resource 
Sirius3
User
Beiträge: 17703
Registriert: Sonntag 21. Oktober 2012, 17:20

Na da schau an, `requests` ist schon installiert.
DeadBarney
User
Beiträge: 4
Registriert: Sonntag 7. Oktober 2018, 13:54

habe den typo korrigiert

mit

Code: Alles auswählen

#coding= UTF-8
import urllib.requests

x = urllib.requests.urlopen('https://www.google.com/')
print(x.read())
kommt trotzdem

Code: Alles auswählen

Traceback (most recent call last):
  File "Bilder.py", line 2, in <module>
    import urllib.requests
ImportError: No module named requests

Benutzeravatar
ThomasL
User
Beiträge: 1366
Registriert: Montag 14. Mai 2018, 14:44
Wohnort: Kreis Unna NRW

Du solltest dich entscheiden ob du urllib.request oder requests benutzen möchtest, aber urllib.requests gibt es nicht
Ich bin Pazifist und greife niemanden an, auch nicht mit Worten.
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
RogerSt
User
Beiträge: 1
Registriert: Freitag 19. Februar 2016, 07:29

Ich bin auch neuling.
Als ich deinen Beitrag gesehen habe, habe ich mal Goole angeschmissen und ca. 30 min später kann ich alle Bilder herunterladen. Somit kann es nicht so schwer sein.
Also ich würde mal die Basics lernen und dann Googlen.

http://lmgtfy.com/?q=python+web+image+download

Ich habe es mir bs4 und urllib gemacht.
Antworten