0 امتیاز

سلام دوستان.

من یه برنامه ساده دارم که میخوام یه لیست از url های سه صفحه html رو بهم در قابل یک فایل json بده. براش نوشتم ک روی دکمه استارت کلیک شد عملیات رو انجام بده.

        private void btnStart_Click(object sender, EventArgs e)
        {
            var web = Statics.OpenBrowser(txtLinkBox.Text);
            string json = "";
            var linkList = web.FindElements(By.XPath("//header[@class='product__header']//h2//a")).ToList();
            foreach (var x in linkList)
            {
                string link =  x.GetAttribute("href");
                string id = "";
                string[] a = link.Split('/');
                int cnt = a.Length - 1;  // Call last index of a array
                Match m = Regex.Match(a[cnt], @"\d{2,}$");
                if (m.Success) { id = m.Groups[0].Value; }
                string demo = @"https://example.com/acc/" + id;

                //Statics.AddToText(link, demo);

                List<data> _data = new List<data>();
                _data.Add(new data()
                {
                    FileUrl = link,
                    DemoUrl = demo,
                    Password = ""

                });

                 json = JsonConvert.SerializeObject(_data.ToArray(), Formatting.Indented);
                //write string to file
                File.AppendAllText(@"D:\path.txt", json);
            }
        }

همه چیز هم درست پیش میشه. ولی خروجی میشه این

[
  {
    "FileUrl": "https://1...",
    "DemoUrl": "https://1...",
    "Password": ""
  }
][
  {
    "FileUrl": "https://2...",
    "DemoUrl": "https://2...",
    "Password": ""
  }
][
  {
    "FileUrl": "https://3...",
    "DemoUrl": "https://3...",
    "Password": "
  }
]

 

در صورتی که من می خوام اینطوری بشه

[
  {
    "FileUrl": "https://1...",
    "DemoUrl": "https://1...",
    "Password": ""
  }
,
  {
    "FileUrl": "https://2...",
    "DemoUrl": "https://2...",
    "Password": ""
  }
,
  {
    "FileUrl": "https://3...",
    "DemoUrl": "https://3...",
    "Password": "
  }
]

در واقع می خوام خروجی یک جیسون یک پارچه باشه.

1 پاسخ

+2 امتیاز
سلام برای گرفتن لینک و ذخیره راههای دیگه هم هست اگر همین پروژه خودتو میخایید سورس رو بزراید اساتید بررسی کنن
سوال جدید

2,337 سوال

2,871 پاسخ

3,725 دیدگاه

3,920 کاربر

دسته بندی ها

...