• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
灬伊天?
博客园    首页    新随笔    联系   管理    订阅  订阅

005-WebBrowser浏览

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using System.Windows.Forms;
 5 
 6 namespace SuperDLL
 7 {
 8     public static class WebBrowser
 9     {
10         public static void Crawler()
11         {
12             System.Timers.Timer time = new System.Timers.Timer(2000);
13             time.Elapsed += (obj, es) =>
14             {
15                 try
16                 {
17                     WebBrowser WinWebBrowser = new WebBrowser();
18                     HtmlDocument doc = WinWebBrowser.Document;
19                     HtmlElement key = doc.GetElementById("id");
20                     key.Focus();
21                     key.InnerText = "Content";
22                     SendKeys.Flush();
23                     key = doc.GetElementById("loginBtn").Children[1].Children[0];
24                     key.Focus();
25                     key.InvokeMember("Click");
26                     SendKeys.Send("{ENTER}");
27                     SendKeys.Flush();
28                 }
29                 catch (Exception er)
30                 {
31                     MessageBox.Show(er.ToString());
32                 }
33             };
34             time.AutoReset = false;
35             time.Enabled = true;
36         }
37     }
38 }
1 foreach (HtmlElement item in doc.GetElementsByTagName("div"))
2 {
3     if (item.GetAttribute("className") == "detail_c")
4     {
5         dl.ShuLiang = item.Children[0].Children[3].OuterText;
6     }
7 }

 

posted @ 2018-09-08 19:36  灬伊天☂  阅读(137)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3