Я посмотрел вокруг Google и его архивы. Есть несколько хороших статей, но никто, кажется, не помогает мне. Поэтому я подумал, что приеду сюда для более конкретного ответа.Python - Как запустить файл .py?
Цель: Я хочу запустить this code на веб-сайте, чтобы сразу получить все файлы с картинками. Это сэкономит много указаний и щелчков.
У меня есть Python 2.3.5 на компьютере с Windows 7 x64. Он установлен в C: \ Python23.
Как я могу заставить этот сценарий «идти», так сказать?
=====================================
WOW. 35k просмотров. Видя, как это верхний результат на Google, вот полезная ссылка я нашел на протяжении многих лет:
http://learnpythonthehardway.org/book/ex1.html
Для установки см упражнение 0.
========= =====================================
FYI: У меня нет опыта работы с Python. Любой совет будет принят во внимание.
В соответствии с просьбой, вот код, я использую:
"""
dumpimages.py
Downloads all the images on the supplied URL, and saves them to the
specified output file ("/test/" by default)
Usage:
python dumpimages.py http://example.com/ [output]
"""
from BeautifulSoup import BeautifulSoup as bs
import urlparse
from urllib2 import urlopen
from urllib import urlretrieve
import os
import sys
def main(url, out_folder="C:\asdf\"):
"""Downloads all the images at 'url' to /test/"""
soup = bs(urlopen(url))
parsed = list(urlparse.urlparse(url))
for image in soup.findAll("img"):
print "Image: %(src)s" % image
filename = image["src"].split("/")[-1]
parsed[2] = image["src"]
outpath = os.path.join(out_folder, filename)
if image["src"].lower().startswith("http"):
urlretrieve(image["src"], outpath)
else:
urlretrieve(urlparse.urlunparse(parsed), outpath)
def _usage():
print "usage: python dumpimages.py http://example.com [outpath]"
if __name__ == "__main__":
url = sys.argv[-1]
out_folder = "/test/"
if not url.lower().startswith("http"):
out_folder = sys.argv[-1]
url = sys.argv[-2]
if not url.lower().startswith("http"):
_usage()
sys.exit(-1)
main(url, out_folder)
Пуск с Учебник Python: http://docs.python.org/tutorial/interpreter.html –