Bharat
Bharat

Reputation: 297

how to make a variable take a html link without formatting in python?

I need to take a url input and use it in subprocess.call().how is it possible? I wanted to write a loop so that it keeps on downloading images until required by doing this

for i in range(1,tot):
    subprocess.call(["wget","http://z.mfcdn.net/store/manga/10543/01-003.0/compressed/beelzebub_3.beelzebub_ch003_%02d.jpg"%num])

to automate this further. is there any way so that the user gives input like http://z.mfcdn.net/store/manga/10543/01-003.0/compressed/beelzebub_3.beelzebub_ch003_%02d.jpg and I can directly insert the variable into subprocess.call().

I Tried the following

urlin=raw_input("input the url: ")
for i in range(1,tot):
    subprocess.call(["wget",urlin\"%num"])

but it is not working.how to make it work.Hope you understood my problem..

Upvotes: 0

Views: 66

Answers (1)

DrHaze
DrHaze

Reputation: 1318

You are declaring i as the iterator for your loop but you use an undeclared num. Here is what I came up with (working on my computer):

import subprocess

numberImages = 3
urlin=raw_input("input the url: ")
for i in range(1,numberImages+1):
    print urlin%i
    subprocess.call(["wget",urlin%i])

used http://z.mfcdn.net/store/manga/10543/01-003.0/compressed/beelzebub_3.beelzebub_ch003_%02d.jpgas raw_input

here is my output:

input the url: http://z.mfcdn.net/store/manga/10543/01-003.0/compressed/beelzebub_3.beelzebub_ch003_%02d.jpg
http://z.mfcdn.net/store/manga/10543/01-003.0/compressed/beelzebub_3.beelzebub_ch003_01.jpg
#Some wget download debug
http://z.mfcdn.net/store/manga/10543/01-003.0/compressed/beelzebub_3.beelzebub_ch003_02.jpg
#Some wget download debug
http://z.mfcdn.net/store/manga/10543/01-003.0/compressed/beelzebub_3.beelzebub_ch003_03.jpg
#Some wget download debug

Upvotes: 1

Related Questions