如何使用 C# 更改 html 中的选定值?

how to change selected value in html using c#?

我正在尝试从网页获取一些数据。我正在用 c# .net 编写代码。该网页有一个下拉列表(或组合框),如下所示。数据根据选定的下拉列表项更改,但 url 不变。我的问题是我的代码如何更改选定的值并从网页获取数据?我解析并只得到了一个这样的项目:

        **WebClient wc = new WebClient();
        string kaynak = wc.DownloadString("http://www.diyanet.gov.tr/");
        string imsak = "spImsak";
        int imindex = kaynak.IndexOf(imsak);
        imindex += 9;
        System.Console.WriteLine(kaynak.Substring(imindex, 5));**

02:44< /span>

我下载了 html 网页代码作为字符串。搜索 "spImsak"。最后我得到了“02:44”作为一个字符串。我想为所有组合框项目做这件事。你能给我什么建议吗?

示例网页:http://www.diyanet.gov.tr/

红色的是组合框。黄色的是我想要得到的数据。

我跟踪了网页的网络,发现当我单击任何下拉列表元素时,网页运行带有参数的网络服务。我解释了如何将其应用于我的问题。

web service and parameters image

我只需要发送 POST 使用这些参数请求此 Web 服务并获得字符串 (json)。我是按照 C# 代码做的。

using (WebClient client = new WebClient())
        {
            int turn;
            byte[] response;
            string result;
            /* gets response for 81 city */
            for (turn = 500; turn < 581; ++turn)
            {

                response =
                client.UploadValues("http://diyanet.gov.tr/PrayerTime/MainPrayerTimesSet", new NameValueCollection()
                {
                    { "countryName", "2" },
                    { "name", turn.ToString() }
                });
                /* without sleep, web service does not response successive requests */
                System.Threading.Thread.Sleep(5);

                /* turns incoming byte[] -> string */ 
                result = System.Text.Encoding.UTF8.GetString(response);

                Console.WriteLine(result);
            }
        }