473,626 Members | 3,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Instead of saving text files i need as html

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.urlretri eve(lines.strip ('/n'), 'c:\\temp\\' \
+ outfilename.str ip('\n')[7:] + '.txt')
except:
pass
-----end-----

Jun 8 '06 #1
7 1484
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.urlretri eve(lines.strip ('/n'), 'c:\\temp\\' \
+ outfilename.str ip('\n')[7:] + '.txt')
except:
pass
-----end-----

Jun 8 '06 #2
"Shani" <Sh******@gmail .com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.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.urlretri eve(lines.strip ('/n'), 'c:\\temp\\' \
+ outfilename.str ip('\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.urlretri eve(lines.strip ('/n'), 'c:\\temp\\' \
+ outfilename.str ip('\n')[7:] + '.html')
except:
pass
-----end-----
Louis
Jun 8 '06 #3
"Shani" <Sh******@gmail .com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.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.urlretri eve(lines.strip ('/n'), 'c:\\temp\\' \
+ outfilename.str ip('\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.writ e('<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.writ e(lines)
except:
pass
newurlfile.writ e('</body> \n</html>')
urlfile.close()
newurlfile.clos e()
-----end-----
Louis
Jun 8 '06 #4
"3c273" <no****@nospam. com> wrote in message
news:e6******** *@enews2.newsgu y.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.writ e('<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.writ e(lines)
except:
pass
newurlfile.writ e('</body> \n</html>')
urlfile.close()
newurlfile.clos e()
-----end-----
Louis

Oops, I guess we don't need "import urllib" anymore.
Louis
Jun 8 '06 #5
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('@')])"
Jun 8 '06 #6
> 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.urlretri eve(lines.strip ('/n'), 'c:\\temp\\' \
+ outfilename.str ip('\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

Jun 8 '06 #7
Tim Chase <ti*@thechases. com> wrote:
[ ... ]
urllib.urlretri eve(lines.strip ('/n'), 'c:\\temp\\' \
+ outfilename.str ip('\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.gr eenend.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
Jun 9 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2346
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. Or how can I replace the html &entities; in a string "blablabla&amp;blablabal&amp;balbalbal" with the chars they mean using re.sub? I found out they are stored in an dict . I though about this functionality:
3
4649
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. Is it possible to go straight from a byte array to document in word instead of a temp file? Also is there a way to change the save behaviour to notify my app to pickup a binary copy of the file or stream to save back to the sql db. Thanks in...
4
6718
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 code ?? thank you Pedro Leite From Portugal ------------------------------------
1
1832
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 strategically somewhere like just before the my variables get declared??? the POST input name is "fileup" so maybe i could call them fileup1, fileup2 etc. This is the upld.pl script itself.
10
2089
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 complicated. I am trying to save the data I need to save and I can fill in some when the necessary data is saved. Vector->piece handle -pointer to the pieces. How do I go about saving that data into a file. I have been doing some research to some...
7
1957
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 have it saved: 1. In a directory by the guides name which would be the variable 'describe11'. Create this directory if it does not already exist. 2. Create a special file name from the date and time submitted.
3
2464
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 the binary data for the file. I can sucessfully take the files out of the databse again and display them in a data grid. I would like to resize the submitted file to a fixed size (say 180 x 120) before I upload it to the database and do this without...
9
1882
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 use to search and print and them add more at another stage , currently i can save and read from these files but only the last person entered is stored and over written each time . i have to use classes and Collections , im using Visual basic 6 my...
6
8063
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 to change the Content- Type and Content-Disposition headers, and essentially print the same report, and it's done. That works fine. But in some reports on the web I need to show images. The web part is fine, but I'm having a tough time...
0
8203
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.