public static List<RegionInfo> GetRegionInfosFromWeb(WebBrowser ie)
{
List<RegionInfo> citys = new List<RegionInfo>();

HtmlElement element = ie.Document.All.GetElementsByName("strCity")[0];
if (element == null) return new List<RegionInfo>();

foreach (HtmlElement el in element.Children)
{
RegionInfo info = new RegionInfo();

el.SetAttribute("Selected", "true");
info.City = el.GetAttribute("Value");
element.InvokeMember("onclick");

Thread.Sleep(1000);

HtmlElement e = ie.Document.All.GetElementsByName("strDistrict")[0];
if (e == null)
{
Debug.WriteLine(string.Format("»ñÈ¡{0}µÄ×ÓµØÇø³ö´í", info.City));
continue;
}

info.SubCitys = new List<string>();
foreach (HtmlElement m in e.Children)
{
m.SetAttribute("Selected", "true");
if (!string.IsNullOrEmpty(m.GetAttribute("value")))
info.SubCitys.Add(m.GetAttribute("value"));
}

citys.Add(info);
}

return citys;
}

webbrowser 采集数据时很好用,遗憾的是不能在非UI线程上工作

相关文章:

  • 2021-05-25
  • 2021-12-11
  • 2021-09-09
  • 2021-06-17
  • 2022-12-23
  • 2022-02-27
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2021-06-12
  • 2022-12-23
  • 2021-07-13
  • 2021-06-15
  • 2021-08-19
  • 2022-12-23
相关资源
相似解决方案