using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.IO;
XmlDocument objXmlDocument = new XmlDocument();
TextReader trs = new StreamReader(Application.StartupPath + "\\LastPostID.txt");
string strLastInsertedId = trs.ReadLine();
trs.Close();
TextWriter tsw1 = new StreamWriter(Application.StartupPath + "\\Status.txt",true);
tsw1.WriteLine(strLastInsertedId + " : " + DateTime.Now.ToString());
tsw1.Close();
label3.Text = strLastInsertedId;
label3.Refresh();
//clsSettings.GetSettingValue((int)clsCommon.Settings.LastPostId);
string strXML = GetXML(strLastInsertedId);
objXmlDocument.LoadXml(strXML);
XmlNodeList objXmlNodeList = objXmlDocument.GetElementsByTagName("listing");
if (objXmlNodeList != null)
{
string strId = string.Empty;
string strTitle = string.Empty;
string strupdatedDate = string.Empty;
string strPrice = string.Empty;
string strPType = string.Empty;
string strURL = string.Empty;
string strCity = string.Empty;
string strState = string.Empty;
for (int i = 0; i < objXmlNodeList.Count; i++)
{
strId = string.Empty;
strTitle = string.Empty;
strupdatedDate = string.Empty;
strPrice = string.Empty;
strPType = string.Empty;
strURL = string.Empty;
strCity = string.Empty;
strState = string.Empty;
if (objXmlNodeList[i]["title"] != null)
{
strTitle = objXmlNodeList[i]["title"].InnerText.ToString();
}
}
}
private string GetXML(string strStartFrom)
{
try
{
string strurl = "http://scrape100.iscrape.org/export/xml/?id=" + strStartFrom;
HttpWebRequest objHttpWebRequest = (HttpWebRequest)WebRequest.Create(strurl);
objHttpWebRequest.Method = "Get";
objHttpWebRequest.ContentLength = 0;
HttpWebResponse objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
Stream objResponseStream = objHttpWebResponse.GetResponseStream();
Encoding objEncoding = Encoding.GetEncoding("utf-8");
StreamReader objStreamReader = new StreamReader(objResponseStream, objEncoding);
string strHtmlOutput = objStreamReader.ReadToEnd();
return strHtmlOutput;
}
catch (Exception ex)
{
return null;
}
}
No comments:
Post a Comment