I'm fairly new to Python, so I'm hoping someone can help me generate a list of unique URLs based on information in a text file.
Example: I have the base URL, www.website.com/users/, and a txt file with usernames, 'frank', 'rachel', 'james', etc. And I want to create URLs with this information, and save it to a txt file, like this:
www.website.com/users/frank
www.website.com/users/rachel
www.website.com/users/james
etc.
I have done something similar with numbers, e.g.
www.website.com/1
www.website.com/2
etc.
The code I wrote for the number solution is pasted below in case it's helpful as a starting point.
import time
htmlTxt=""
pageNum=0
x="http://forum.com/eforum/forumdisplay.php?fid=13&page="
y=x+str(pageNum)
file = open("URLs.txt", "wb")
while True:
try:
time.sleep(0.001) # do something here
file.write(x +str(pageNum)+"\n")
pageNum+=1
except KeyboardInterrupt:
print '\nPausing... (Hit ENTER to continue, type quit to exit.)'
try:
response = raw_input()
if response == 'quit':
break
print 'Resuming...'
except KeyboardInterrupt:
print 'Resuming...'
continue
file.close()
(the reason I used 'time' in the example above is because I don't know how to make it stop at a certain number, so I just let it ran for a few seconds and deleted the URLs that went beyond the 'max' number.)
Thanks in advance!
www.website.comthe same site every time in the expected output? Where does it come from? What does the list of names look like? One per line in a file?