עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

עזרה בקריאת אתרים בעזרת C#

Featured Replies

פורסם

התחלתי להשתמש בקוד שקורא תוכן של אתרים אחרי שנותנים לו את הURL...

הפלט שאני מקבל הוא את כל קוד ה HTML... יש אפשרות לקבל רק את התוכן עצמו?

זאת אומרת ממש לקרוא את התוכן כפי שנקרא בדפדפן?

זה הקוד :





private void button1_Click(object sender, EventArgs e)
{
string URL = textBox1.Text;
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
WebClient client = new WebClient();
richTextBox1.Text = result;
sr.Close();
myResponse.Close();
}


פורסם

HTML הוא מקרה פרטי של XML, אשר מחולק לטאגים.

תפרסר אותו לפי איזה טאגים שאתה בוחר.

בC# יש ספרייה שלמה של עבודה עם XML, אבל ננסה לצורך הדוגמה לנסות להבין את זה בצורה ידנית.

אתה צריך להתחיל לקרוא תוכן בסיום כל תחילית של טאג, למשל

<H1>some text</H1>

לכן תחפש תחילה את התו ">", אחריו תמיד תופיע מילת הזיהוי שלו, ואחריה תחפש את התו שסוגר ("<") מכאן אתה כבר צריך לקרוא את הטקסט (כל עוד אין לך פתיחת עטאג נוסף!)

תתחיל מה BODY, תיצור לעצמך ספרייה מיוחדת שיודעת להתעסק עם כל סוגי הטאגים, ממש כמו שגוגל יודעת לעשות.

ובאמת תציץ בגוגל, בטוח מישהו כבר הכין כזהדבר.

בהצלחה.

פורסם
  • מחבר

אחלה תודה!

ניסיתי לעשות את מה שאתה אומר והסתבכתי קצת...

 



StreamReader sr = new StreamReader("\\text.txt");
string body = sr.ReadToEnd();


List<int> start = new List<int>();
List<int> end = new List<int>();





int i = 0;

while ((i = body.IndexOf('<', i)) != -1)
{
start.Add(i);
i++;

}


int j = 0;

while ((j = body.IndexOf('>', j)) != -1)
{
end.Add(j);
j++;

}



char[] b = new char[body.Length];
StringReader sr1 = new StringReader(body);


for (int a = 0; (a < (start.Count - 1)); a++)
{
int seglenght = (start[a + 1] - end[a]);
sr1.Read(b, end[a], seglenght);



}


string cleantext = "";
StringBuilder sb = new StringBuilder(cleantext);
StringWriter sw = new StringWriter(sb);
sw.Write(b, 0, 3);
sw.Close();


richTextBox1.Text = cleantext;



sr1.Close();


איפה הטעות? זה מה שראיתי באינטרנט שצריך לעשות...תודה מראש!

פורסם
  • מחבר

אוקיי הצלחתי... אז חשבתי שכדאי לשתף ולתרום קצת במקום סתם להציק עם שאלות צעירות!




string text = before.Text;


//finding '<' + '>' positions
//==================


List<int> start = new List<int>();
int i =0;


while ((i = text.IndexOf('<', i)) != -1)
{
start.Add(i);
i++;

}


List<int> end = new List<int>();
int j = 0;


while ((j = text.IndexOf('>', j)) != -1)
{
end.Add(j);
j++;
}


// removing <tags>


for (int c = (start.Count-1) ; c >= 0 ; c--)
{
text = text.Remove(start[c], ((end[c]+1) - (start[c])));
}


after.Text = text;
}

פורסם

שים לב שיש לזה מיליון סיפריות, מהניסיון שלי html agility pack מצויינת.

http://htmlagilitypack.codeplex.com/

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.