using
HtmlAgilityPack;
using System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.IO;
using
System.Linq;
using
System.Net;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows.Forms;
//< add
using >
using html
=HtmlAgilityPack;
//</
add using >
namespace
webrobot_ebayKleinanzeigen
{
public partial class frmWebRoboter : Form
{
//----------<
global>----------
html.HtmlDocument _doc;
//----------</
global>----------
#region Form
//-------------------<
region: Forms >---------- --------
public
frmWebRoboter()
{
InitializeComponent();
}
//-------------------</
region: Forms >---------- --------
#endregion /Form
#region Buttons
//-------------------<
region: Buttons >---------- --------
private void
btnRead_Click(object sender, EventArgs e)
{
fl_Test();
}
//-------------------</
region: Buttons >---------- --------
#endregion
#region Methods
//-------------------<
region: Methods >------------------
private void fl_Test()
{
//----------------<
fl_Test() >----------------
string sURL =
tbxURL.Text;
sys_Add_Log("Get
Website");
WebRequest
objRequest = WebRequest.Create(sURL);
HttpWebResponse
objResponse = (HttpWebResponse)
objRequest.GetResponse();
sys_Add_Log("/Get
Website");
sys_Add_Log("Text auslesen");
//< Webseite auslesen >
Stream
objDataStream = objResponse.GetResponseStream();
//</
Webseite auslesen >
//<
Text auslesen >
StreamReader
TextReader = new StreamReader(objDataStream);
//</
Text auslesen >
//< get
HTMLdocument >
string sHTML =
TextReader.ReadToEnd();
_doc = new html.HtmlDocument();
_doc.LoadHtml(sHTML);
//</
get HTMLdocument >
sys_Add_Log("/Text
auslesen");
//< anzeigen >
tbxHTML.Text =
sHTML;
//</ anzeigen >
sys_Add_Log("/anzeigen");
//< Abschluss >
TextReader.Close();
objDataStream.Close();
objResponse.Close();
//</ Abschluss >
//< auswerten >
get_Results();
//----------------</ fl_Test()
>----------------
}
#region Auswerten
private void
get_Results()
{
//-------------------<
get_Results() >-------------------
HtmlNodeCollection nodes =
_doc.DocumentNode.SelectNodes("//h2[@class='text-module-begin']");
foreach (HtmlNode n in nodes)
{
HtmlNode a =
n.SelectSingleNode("a");
string sTitel =
a.InnerText;
string sURL =
a.GetAttributeValue("href","");
sys_Add_Result(sTitel);
}
//-------------------</
get_Results() >-------------------
}
#endregion
//-------------------</
region: Methods >------------------
#endregion
#region System
//-------------------</
region: System Methods >------------------
private void
sys_Add_Log(string parText = "")
{
//----------------------<
sys_Add_Log() >----------------------
string sText =
tbxLog.Text;
sText = DateTime.Now.ToLongTimeString()
+ " " + parText + Environment.NewLine +
sText;
//< automatisch kuerzen >
if (sText.Length > 10000)
{ sText =
sText.Substring(1, 10000); }
//</ automatisch kuerzen >
tbxLog.Text
= sText;
//----------------------</
sys_Add_Log() >----------------------
}
private void
sys_Add_Result(string parText = "")
{
//----------------------<
sys_Add_Log() >----------------------
string sText =
tbxResult.Text;
sText = DateTime.Now.ToLongTimeString()
+ " " + parText + Environment.NewLine +
sText;
//< automatisch kuerzen >
if (sText.Length > 10000)
{ sText =
sText.Substring(1, 10000); }
//</ automatisch kuerzen >
tbxResult.Text
= sText;
//----------------------</
sys_Add_Log() >----------------------
}
//-------------------</ region:
System Methods >------------------
#endregion
}
}
|