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
Bilder einer Website herunterladen
- 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.
- __blackjack__
- User
- Beiträge: 13218
- 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.
“There will always be things we wish to say in our programs that in all known languages can only be said poorly.” — Alan J. Perlis
-
- 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
kann es sein, dass es nicht funktioniert, weil ich Ubuntu verwende?
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())
habe es nach dieser website runtergeladen: https://stackoverflow.com/questions/173 ... d-requestsImportError: No module named request
kann es sein, dass es nicht funktioniert, weil ich Ubuntu verwende?
- __blackjack__
- User
- Beiträge: 13218
- 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.
Ich persönlich würde ja das externe `requests`-Modul für so etwas verwenden.
“There will always be things we wish to say in our programs that in all known languages can only be said poorly.” — Alan J. Perlis
-
- 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
-
- User
- Beiträge: 4
- Registriert: Sonntag 7. Oktober 2018, 13:54
habe den typo korrigiert
mit
kommt trotzdem
mit
Code: Alles auswählen
#coding= UTF-8
import urllib.requests
x = urllib.requests.urlopen('https://www.google.com/')
print(x.read())
Code: Alles auswählen
Traceback (most recent call last):
File "Bilder.py", line 2, in <module>
import urllib.requests
ImportError: No module named requests
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
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
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.
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.