• 1399/03/26

ثبت اطلاعات از سایت در سی شارپ :

سلام من این کد رو نوشتم که عدد eps  از سایت نماد شبندر بورس بگیرم توسط سی شارپ و در لیبل چام بشه بعد از زدن دکمه دget  اما نم اید و notfound میآید لطفا بگین کجاش اشتباه هست و چه تغیراتی داخلش بدم

 

using System;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;

namespace GetDigikalaPrice
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "35366681030756042"; // Product ID (dkp-711783)
            button1.Text = "Get";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Text = "Wait...";
            button1.Enabled = false;
            Application.DoEvents();
            var url = "http://www.tsetmc.com/Loader.aspx?ParTree=151311&i=" + textBox1.Text;
            var page = GetPage(url);
            var classId = "connKO";
            var regex = new Regex("<td>"+"1060:"+"</td>", RegexOptions.IgnoreCase);
            var match = regex.Match(page);
            label1.Text = (match.Success) ? match.Groups["price"].Value : "Not found!";
            button1.Text = "Get";
            button1.Enabled = true;
        }

        private static string GetPage(string url)
        {
            try
            {
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.CookieContainer = new CookieContainer();
                request.Proxy = WebRequest.DefaultWebProxy;
                request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36";
                request.ProtocolVersion = HttpVersion.Version10;
                request.Accept = "*/*";
                request.ContentType = "text/html";
                request.ContentLength = 0;
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    var stream = response.GetResponseStream();
                    if (stream == null)
                    {
                        return string.Empty;
                    }
                    using (var reader = new StreamReader(stream))
                    {
                        return reader.ReadToEnd();
                    }
                }
            }
            catch
            {
                return "";
            }
        }
    }
}
logo-samandehi