473,412 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Retrieving code of a particular URL

Hi,
I am trying to retrieve the source code of a particular url, but it
seems that I am doing something wrong.

HttpWebRequest webRequest;
HttpWebResponse webResponse;
StreamReader reader;
string text="";
int pos=-1;

webRequest = (HttpWebRequest) WebRequest.Create(data);
webResponse = (HttpWebResponse) webRequest.GetResponse();
reader = new StreamReader(webResponse.GetResponseStream(),
Encoding.ASCII);
text = reader.ReadToEnd();
pos = text.IndexOf(" out of 5 stars", 0);

The variable data containds a URL address such as the following-
http://www.amazon.com/exec/obidos/AS...6link_code=sp1

When I enter in the link manually, enter in View Source and make a
search for " out of 5 stars", the data is found, but when I do it
within the code, that string is not found.

Can someone give me some help.
Thanks in Advance
Nov 16 '05 #1
5 1159
Hi Xarky,

I doubt the web page is ASCII encoded. Most likely it is UTF-8 encoded,
which is the default encoding for the StreamReader class or standard 8-bit
(ISO-8859-1). You can detect the encoding using the
HttpWebResponse.ContentEncoding or by reading the CHARSET in the source.
See the thread "Is this an encoding problem". However, checking the page
I found no encoding markers whatsoever.

Btw, using UTF-8 I found "out of 5 stars" at position 19421.
I should go nag Amazon about their horribly non standard html code.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

I changed this line with Encoding.UTF8, but it is still not finding me
the data told.

reader = new StreamReader(webResponse.GetResponseStream(),
Encoding.UTF8);

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi xarky,

Upon further examination it appears the encoding isn't to blame after all.
In fact there is no " out of 5 stars" in the source at all.
There is a linebreak before "out", so " \nout of 5 stars" will give the
correct value.

If there is always a linebreak at that position you will be fine,
otherwise you might want to strip away all linebreaks before searching.
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4

Hi,

is there another way of downloading html code from that shown below,
because its not working correctly, where it must be working.

HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(data);
HttpWebResponse webResponse = (HttpWebResponse)
webRequest.GetResponse();
StreamReader reader = new StreamReader(webResponse.GetResponseStream(),
Encoding.UTF8);
text = reader.ReadToEnd();

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Xarky,

Your method should work, but unlike searching in internet explorer you
will need to beware of linebreaks when using IndexOf. The downloaded text
is exactly the same as Internet Explorer sees.

Other methods of downloading can be using
WebClient.DownloadFile/DownloadData or reading bytes from the Stream you
get from HttpWebResponse.GetResponseStream(). The downloaded text would
be the same as your method.

It may be that a Regex pattern will allow you to search for " out of 5
stars" and allow for linebreaks inside the pattern.
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #6

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

Similar topics

1
by: haroldsphsu | last post by:
Hi all, I have an application that creates a publication on the server, and have multiple mobile devices creating annonymous subscriptions to that publications. I need to write a report that...
0
by: James Griffiths | last post by:
Here is a report I've written about a printing problem that is being experienced by a particular company for whom I had developed a A97 system. After upgrading to Win XP and AXP, some printing...
2
by: Sagaert Johan | last post by:
Hi I have set the columreorder to true Is there a way to get/set the current columnorder, so i can restore the order from a saved setting ? Johan
0
by: Brian Conway | last post by:
How can I code something to pull a particular cells information in a datagrid and assign it to a variable? I have a button that I want to user to click on, and when they do this it will pull the...
0
by: Diffident | last post by:
Hello All, Was wondering if we could retrieve the index of a particular row from a dataset's table based on the filter criteria for the row? For example, I have 4 rows in my datatable which...
1
by: Glenn T. Kitchen | last post by:
Dear Group, I'm having problems retrieving the child rows of a parent row. The parent table is Users and the child table is Addresses. I used the Schema to create a DataRelation between the...
10
by: Bhavna | last post by:
I am using a Replace function to replace single quotes with double when submitting a text field in the database i.e. Replace (q, "'", "' ' ") which works fine. When I retrieve the field from the...
6
by: naughtybynature | last post by:
Hello I would like to know if there's any possible code for retrieving id when we use button. Normally the button itself will only functions if we use form action, however if i only used that...
3
by: ajos | last post by:
Hello friends, In my action class i am getting a resultset data which im storing in a arraylist. In my jsp page im retrieving the arraylist data as-----> <%publicity.PendingReqForm prfObj=null;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
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,...
0
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...

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.