private string downloadContent()
{
try
{
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
response = request.GetResponse();
Stream stream = response.GetResponseStream();
reader = new StreamReader(stream);
string content = reader.ReadToEnd();
return content;
}
catch
{
return error;
}
}
The result is :
14/08/2012 22:22:11===> ��'���� ���� ���� ������ ���� ������ ������
14/08/2012 22:22:11===> ������ ������ 14/08/2012
14/08/2012 22:22:11===> ������� ���� �������� ����� ��� ������ ���� �� 2 ������
14/08/2012 22:22:11===> ��'��� ��'��� ��� ������ �''�
14/08/2012 22:22:11===> ''�� ������ ����� �� ��� ������� �����''
14/08/2012 22:22:11===> ��� ������ ������: ������ �� ����� ��� ��� �� ��������
14/08/2012 22:22:11===> ���: ����� ��� ��� ���� �� ����-����� ���� ����� �� ����
14/08/2012 22:22:11===> ��''�: ��'���� ������ ����� ����� ����� ������� ������� ��-������
14/08/2012 22:22:11===> ����� ���� ��� ����� �� ���� ���� ���� ���� ������
14/08/2012 22:22:11===> ����� ���� ������ �������: ''����� ������ �� ���� 2013''
14/08/2012 22:22:11===> ���� ������ �����: ���� ���� ������� ������
14/08/2012 22:22:11===> ��� ���: ���� ������ ����� �� ������ ���������� ���� ����� ������- ������ ����..
While the source of the website page is like this:
<TD ALIGN="RIGHT" VALIGN="TOP"> <font size=-1 color=#ff9933><b>3077</b></font> </TD></TR><TR BGCOLOR="#FDFDFD">
<TD ALIGN="RIGHT" VALIGN="TOP">
<body onmousemove="overhere()">
<a onmouseover="EnterContent('ToolTip','פיקוד העורף יערוך ביומיים הקרובים 5 תרגילים בצפון','<u><span style=color:#000099;>כתב: Bloops בתאריך: 14.08.12 שעה: 21:39</span></u><br>פיקוד העורף יקיים מחר (רביעי) ומחרתיים מספר תרגילים באזור טבריה, עפולה, מגדל העמק ונצרת. מחר בבוקר יתקיים תרגיל המדמה נפילת טילים באזור כלא גלבוע במוע...'); Activate();" onmouseout="deActivate()" href="javascript:void(0)">
<img src="http://rotter.net/forum/Images/new_icon_general.gif" border="0"></a></TD><TD ALIGN="right" VALIGN="TOP" WIDTH="55%">
<FONT CLASS='text15bn'><FONT FACE="Arial">
<a href="http://rotter.net/cgi-bin/forum/dcboard.cgi?az=read_count&om=18520&forum=scoops1"><b>פיקוד העורף יערוך ביומיים הקרובים 5 תרגילים בצפון</b>
</a></font></TD>
<TD ALIGN="CENTER" VALIGN="TOP">
<FONT SIZE="2" COLOR="#000099"
FACE="Arial"><font size=1 color=000099>14.08.12 <font size=1 color=red>21:39</font><br>
<a href="http://rotter.net/cgi-bin/forum/dcboard.cgi?az=user_profiles&user=Bloops"><font CLASS='text13'><b>Bloops</b></font></a></FONT></TD>
<TD ALIGN="CENTER" VALIGN="TOP"><FONT SIZE="1"
COLOR="#000099" FACE="Arial">14.08.12<font color="#FDFDFD" size="1"> </font><font color=red>21:39</font> <br>מאת Bloops</FONT></TD>
<TD ALIGN="CENTER" VALIGN="TOP"><FONT
SIZE="2" COLOR="#000099" FACE="Arial"><b>0
</b></FONT></TD>
<TD ALIGN="RIGHT" VALIGN="TOP"> <font size=-1 color=#ff9933><b>בעדכון</b></font> </TD></TR><TR BGCOLOR="#eeeeee">
<TD ALIGN="RIGHT" VALIGN="TOP">
<body onmousemove="overhere()">
<a onmouseover="EnterContent('ToolTip','תשואה’’ מדהימה למדינה: כל מצלמת מהירות עולה 180 א’ ש’ח','<u><span style=color:#000099;>כתב: elbaz בתאריך: 14.08.12 שעה: 19:35</span></u><br>עמוד "דחליל" עולה 140 א’ ש’ ותפעול - 22 מיליון שקל; הרווח מהדוחות? מאות מיליונים בשנה<br>עמוד ריק עולה כמו ניידת משטרה חדשה `...'); Activate();" onmouseout="deActivate()" href="javascript:void(0)">
<img src="http://rotter.net/forum/Images/new_icon_general.gif" border="0"></a></TD><TD ALIGN="right" VALIGN="TOP" WIDTH="55%">
<FONT CLASS='text15bn'><FONT FACE="Arial">
<a href="http://rotter.net/cgi-bin/forum/dcboard.cgi?az=read_count&om=18489&forum=scoops1"><b>תשואה'' מדהימה למדינה: כל מצלמת מהירות עולה 180 א' ש'ח</b>
</a></font></TD>
<TD ALIGN="CENTER" VALIGN="TOP">
<FONT SIZE="2" COLOR="#000099"
FACE="Arial"><font size=1 color=000099>14.08.12 <font size=1 color=red>19:35</font><br>
<a href="http://rotter.net/cgi-bin/forum/dcboard.cgi?az=user_profiles&user=elbaz"><font CLASS='text13'><b>elbaz</b></font></a></FONT></TD>
<TD ALIGN="CENTER" VALIGN="TOP"><FONT SIZE="1"
COLOR="#000099" FACE="Arial">14.08.12<font color="#eeeeee" size="1"> </font><font color=red>21:38</font> <br>מאת גדליה הפיל</FONT></TD>
<TD ALIGN="CENTER" VALIGN="TOP"><FONT
SIZE="2" COLOR="#000099" FACE="Arial"><b>4
</b></FONT></TD>
And im downloading the text between the tags:
private void GetText(string text)
{
names = new List<string>();
string startTag = "forum=scoops1\"><b>";
string endTag = "</b>";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
index = 0;
while (true)
{
index = text.IndexOf(startTag, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
index = text.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
profileName = text.Substring(start, index - start);
names.Add(profileName);
}
}
While text is the content source of the website page.
The question is why im getting this symbols instead text and if there is anyway to repair it ?
Im using same code for another site wich im not having this problem.
You need to use the correct encoding in order to read the returned stream values.
Make sure that you are using the same encoding that the page is in (will either be in the HTTP headers or a
metaelement on the page – thecontent-typeof the page).Use that encoding to get the correct string representation of the bytes.