I have the following code which takes a list of urls
"http://google.com", without the quotes ofcourse, and then saves there
source code as a text file. I wan to alter the code so that for the
list of URLs an html file is saved.
-----begin-----
import urllib
urlfile = open(r'c:\temp\url.txt', 'r')
for lines in urlfile:
try:
outfilename = lines.replace('/', '-')
urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \
+ outfilename.strip('\n')[7:] + '.txt')
except:
pass
-----end----- 7 1474
Then just write HTML around your list. I would guess
you want them inside a table. Just write appropriate
HTML tags before/after the urls. If you want the URLs
to be clickable make them in into <a href>url</a> lines.
-Larry Bates
Shani wrote: I have the following code which takes a list of urls "http://google.com", without the quotes ofcourse, and then saves there source code as a text file. I wan to alter the code so that for the list of URLs an html file is saved.
-----begin----- import urllib urlfile = open(r'c:\temp\url.txt', 'r') for lines in urlfile: try: outfilename = lines.replace('/', '-') urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \ + outfilename.strip('\n')[7:] + '.txt') except: pass -----end-----
"Shani" <Sh******@gmail.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com... I have the following code which takes a list of urls "http://google.com", without the quotes ofcourse, and then saves there source code as a text file. I wan to alter the code so that for the list of URLs an html file is saved.
-----begin----- import urllib urlfile = open(r'c:\temp\url.txt', 'r') for lines in urlfile: try: outfilename = lines.replace('/', '-') urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \ + outfilename.strip('\n')[7:] + '.txt') except: pass -----end-----
Is this what you mean?
-----begin-----
import urllib
urlfile = open(r'c:\temp\url.txt', 'r')
for lines in urlfile:
try:
outfilename = lines.replace('/', '-')
urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \
+ outfilename.strip('\n')[7:] + '.html')
except:
pass
-----end-----
Louis
"Shani" <Sh******@gmail.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com... I have the following code which takes a list of urls "http://google.com", without the quotes ofcourse, and then saves there source code as a text file. I wan to alter the code so that for the list of URLs an html file is saved.
-----begin----- import urllib urlfile = open(r'c:\temp\url.txt', 'r') for lines in urlfile: try: outfilename = lines.replace('/', '-') urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \ + outfilename.strip('\n')[7:] + '.txt') except: pass -----end-----
Or is this what you mean?
-----begin-----
import urllib
urlfile = open('c:\\temp\\url.txt', 'r')
newurlfile = open('c:\\temp\\newurls.html', 'w')
newurlfile.write('<html> \n<body>\n')
for lines in urlfile:
try:
if lines == '\n':
pass
else:
lines = '<a href="' + lines.strip() +'">'\
+ lines.strip() + '</a>' + '<br>\n'
newurlfile.write(lines)
except:
pass
newurlfile.write('</body> \n</html>')
urlfile.close()
newurlfile.close()
-----end-----
Louis
"3c273" <no****@nospam.com> wrote in message
news:e6*********@enews2.newsguy.com... Or is this what you mean? -----begin----- import urllib urlfile = open('c:\\temp\\url.txt', 'r') newurlfile = open('c:\\temp\\newurls.html', 'w') newurlfile.write('<html> \n<body>\n') for lines in urlfile: try: if lines == '\n': pass else: lines = '<a href="' + lines.strip() +'">'\ + lines.strip() + '</a>' + '<br>\n' newurlfile.write(lines) except: pass newurlfile.write('</body> \n</html>') urlfile.close() newurlfile.close() -----end----- Louis
Oops, I guess we don't need "import urllib" anymore.
Louis
Shani wrote: I have the following code which takes a list of urls "http://google.com", without the quotes ofcourse, and then saves there source code as a text file. I wan to alter the code so that for the list of URLs an html file is saved.
What you write in a text file is up to you - and AFAICT, HTML is still
a text format.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
> Is this what you mean? -----begin----- import urllib urlfile = open(r'c:\temp\url.txt', 'r') for lines in urlfile: try: outfilename = lines.replace('/', '-') urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \ + outfilename.strip('\n')[7:] + '.html') except: pass -----end-----
[laughs] I suspect the urlretrieve line should contain
"strip('\n')" instead of "strip('/n')", but otherwise, the
original code looked pretty kosher. I'm not sure what the odd
slicing is for, but I'll presume the OP knows what they're doing.
While not a python solution, the standard *nix tool would be
either wget or curl:
bash> wget -i listofurls.txt
which is freely available with the Cygwin suite of GNU tools for
Win32 platforms.
-tkc
Tim Chase <ti*@thechases.com> wrote: [ ... ] urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \ + outfilename.strip('\n')[7:] + '.html') [ ... ] I'm not sure what the odd slicing is for, but I'll presume the OP knows what they're doing.
It's taking the "http://" off the front of the URL. len("http://")
7
--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lukas Holcik |
last post by:
Hi everyone!
How can I simply search text for regexps (lets say <a
href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a
dictionary { name : URL}? In a single pass if it could....
|
by: tigrrgrr42 |
last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am
currently bringing them from a byte array into a temp file to pop into word
and make word do its thing as a com object. ...
|
by: Pedro Leite |
last post by:
Good Afternoon.
the code below is properly retreiving binary data from a database and saving
it. but instead of saving at client machine is saving at the server machine.
what is wrong with my...
|
by: fatjoez |
last post by:
Hey there.
I've been trying to modify my file upload script so that it handles 10 files instead of one.
i was thinking the most straightforward way would be to add a FOR LOOP? placed...
|
by: JoeC |
last post by:
I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more...
|
by: Dave Kelly |
last post by:
There has to be a name for what I want to do and I don't know what words
to google for.
I have a form here:
http://www.texasflyfishers.org/firstpage.htm
I want to submit it to the server and...
|
by: pozze |
last post by:
Hi,
I've just made the change from ASP to .net.
I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly...
|
by: Yamasassy |
last post by:
HI im having problems to saving to a .txt file, i need to be able to store a number of employees to this file (and beable to open and these files to load in to text boxes)and retrieve then for later...
|
by: Eddie |
last post by:
Hi all,
I am displaying a number of reports, and giving the users an option to
display them on the web or download them to Excel. If they want the
Excel file, I just use the PHP header command...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |