From the code in your comment (you should put this in your question), it is with reading the lines from a file that you’re struggling.
The idiomatic way of doing this is like so:
with open("hello.txt") as f:
for line in f:
print line,
[See File Objects in the official Python documentation].
Plugging this into your code (and removing the newline and any spaces from each line with str.strip()
):
#!/usr/bin/env python
import mechanize
br = mechanize.Browser()
br.set_handle_redirect(False)
with open('urls.txt') as urls:
for url in urls:
stripped = url.strip()
print '[{}]: '.format(stripped),
try:
br.open_novisit(stripped)
print 'Funfando!'
except Exception, e:
print e
Note that URLs start with a scheme name (commonly called a protocol, such as http
), followed by a colon, and two slashes hence:
[stackoverflow.com]: can’t fetch relative reference: not viewing any document
But
[http://stackoverflow.com/]: Funfando!
2
solved Check if many URLs exists from a txt file (Python) [closed]