| | |
how to read content of html page and save in text file
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 17
Reputation:
Solved Threads: 0
hello friend
i have a text file name url.txt contain lots of url, one url in a line.
now i want to get the content of each an every page which are open on the basis of those urls,
here is my code:
its working and show the content of the file in console but the records are repeated.
that mean content of 1st then 1st and 2nd then 1st 2nd 3rd.
but i want the records are unique.
for example 5 url 5 records.
this code give me 15.
plz help me what is the problem in that code??
that is the content of url.txt:
i have a text file name url.txt contain lots of url, one url in a line.
now i want to get the content of each an every page which are open on the basis of those urls,
here is my code:
using System;
using System.IO;
using System.Net;
using System.Text;
class WebFetch
{
static void Main(string[] args)
{
// used to build entire input
StringBuilder sb = new StringBuilder();
// used on each read operation
byte[] buf = new byte[8192];
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:/wamp/www/isbn/url.txt");
while ((line = file.ReadLine()) != null)
{
// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(line);
// execute the request
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);
// continue building the string
sb.Append(tempString);
}
}
while (count > 0); // any more data to read?
// print out page source
Console.WriteLine(sb.ToString());
}
file.Close();
}
}its working and show the content of the file in console but the records are repeated.
that mean content of 1st then 1st and 2nd then 1st 2nd 3rd.
but i want the records are unique.
for example 5 url 5 records.
this code give me 15.
plz help me what is the problem in that code??
that is the content of url.txt:
C# Syntax (Toggle Plain Text)
https://isbndb.com/api/books.xml?access_key=RPGYD5PC&index1=isbn&value1=3890071341 https://isbndb.com/api/books.xml?access_key=RPGYD5PC&index1=isbn&value1=8831754750 https://isbndb.com/api/books.xml?access_key=RPGYD5PC&index1=isbn&value1=0941419940 https://isbndb.com/api/books.xml?access_key=RPGYD5PC&index1=isbn&value1=0941419711 https://isbndb.com/api/books.xml?access_key=RPGYD5PC&index1=isbn&value1=3921029570
sandipan.rcciit,
Remove the content of StringBuilder object after printing it on console window.
Remove the content of StringBuilder object after printing it on console window.
C# Syntax (Toggle Plain Text)
sb.Length=0;
![]() |
Similar Threads
- How can I read a pdf web page? (Python)
- How do I output information from a PHP page to an HTML page? (PHP)
- Read contents of external text file into html page (HTML and CSS)
- To write a text file in FTP server (ASP)
- Extract field from text file (Java)
- help me about save and not save text file (Visual Basic 4 / 5 / 6)
- conversion of text file into data base file (Visual Basic 4 / 5 / 6)
- Output to text (notepad) file (HTML and CSS)
- not sure how to save fscanf to file (C++)
- Save a text file in an csv.file with ascii? (PHP)
Other Threads in the C# Forum
- Previous Thread: Sqlbulkcopy log
- Next Thread: problems with webservices
Views: 1288 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast button c# chat check checkbox class client code color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption event excel file files form format forms ftp function gcd gdi+ http httpwebrequest image index input install java label list listbox listener login math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource saving serialization server sleep socket sql statistics stream string tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






