{"id":1673,"date":"2017-07-12T11:43:29","date_gmt":"2017-07-12T02:43:29","guid":{"rendered":"http:\/\/okamurax.com\/?p=1673"},"modified":"2017-08-02T09:49:15","modified_gmt":"2017-08-02T00:49:15","slug":"c-web%e3%82%b5%e3%82%a4%e3%83%88%e8%aa%ad%e8%be%bc","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=1673","title":{"rendered":"C# Web\u30b5\u30a4\u30c8\u8aad\u8fbc"},"content":{"rendered":"<p>\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u304cIE\u306b\u306a\u308b\u3088\u3046\u3067\u3001IE\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u5909\u66f4\u306f\u30ec\u30b8\u30b9\u30c8\u30ea\u304b\u3089\u306e\u307f\u3002<br \/>\n\u6bce\u56de\u3001DocumentCompleted\u304c\u8d70\u308b\u306e\u3067\u7121\u9650\u30eb\u30fc\u30d7\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u6ce8\u610f\u3002<\/p>\n<pre class=\"lang:c# decode:true \">using System;\r\nusing System.Collections.Generic;\r\nusing System.ComponentModel;\r\nusing System.Data;\r\nusing System.Drawing;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nusing System.Windows.Forms;\r\n\r\nnamespace WindowsFormsApp1\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n            webBrowser1.ScriptErrorsSuppressed = true;\r\n            webBrowser1.Navigate(\"https:\/\/weather.yahoo.co.jp\/weather\/jp\/xxx\");\r\n            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(tenki);\r\n        }\r\n\r\n        private void tenki(object sender, WebBrowserDocumentCompletedEventArgs e)\r\n        {\r\n\r\n            HtmlElementCollection hec = webBrowser1.Document.All;\r\n\r\n            foreach (HtmlElement he in hec)\r\n            {\r\n\r\n                if (he.GetAttribute(\"className\").ToString() == \"forecastCity\")\r\n                {\r\n                    \/* \u4ee5\u4e0b\u306e\u3088\u3046\u306b\u76f4\u63a5CSS\u3092\u66f8\u3044\u3066\u3082\u5927\u4e08\u592b\r\n                    webBrowser1.DocumentText =\r\n                        \"&lt;style&gt;\" +\r\n                        \"*{font: normal 12px;}\" +\r\n                        \"th,tr,td{padding: 10px; border: 1px solid #ccc;}\" +\r\n                        \"table{border-collapse: collapse; text-align: center}\" +\r\n                        \"&lt;\/style&gt;\" +\r\n                        \"&lt;table&gt;\" + he.InnerHtml + \"&lt;\/table&gt;\";\r\n                    *\/\r\n                    webBrowser1.DocumentText = \"&lt;html&gt;&lt;head&gt;\" +\r\n                        \"&lt;link rel='stylesheet' href='\/\/s.yimg.jp\/images\/weather\/pc\/v2\/css\/weatherCommon-2.1.0.css'&gt;\" + \r\n                        \"&lt;link href='https:\/\/s.yimg.jp\/yui\/jp\/mh\/pc\/1.4.8\/css\/std.css' rel='stylesheet' type='text\/css' media='all'&gt;\" + \r\n                        \"&lt;\/head&gt;\" +\r\n                        \"&lt;body&gt;&lt;div&gt;\" + he.InnerHtml + \"&lt;\/div&gt;&lt;\/body&gt;&lt;\/html&gt;\";\r\n\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u8aad\u307f\u8fbc\u3080\u3053\u3068\u3082\u53ef\u80fd\u3002<\/p>\n<pre class=\"lang:c# decode:true \">using System;\r\nusing System.Collections.Generic;\r\nusing System.ComponentModel;\r\nusing System.Data;\r\nusing System.Drawing;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nusing System.Windows.Forms;\r\n\r\nnamespace WindowsFormsApp1\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        Boolean isLoad = false;\r\n\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n\r\n            webBrowser1.ScriptErrorsSuppressed = true;\r\n            \r\n            webBrowser1.Navigate(\"xxx\");\r\n            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(LoadPage);\r\n\r\n            timer1.Start();\r\n        }\r\n\r\n        private void LoadPage(object sender, WebBrowserDocumentCompletedEventArgs e)\r\n        {\r\n            if (isLoad== true) return;\r\n\r\n            HtmlElementCollection hec = webBrowser1.Document.Body.All;\r\n\r\n            string body = \"\";\r\n\r\n            \/\/class\r\n            foreach(HtmlElement he in hec)\r\n            {\r\n                if(he.GetAttribute(\"className\").ToString() == \"xxx\")\r\n                {\r\n                    body += he.InnerHtml;\r\n                }\r\n            }\r\n\r\n            \/* ID\r\n            foreach (HtmlElement he in hec)\r\n            {\r\n                if (he.Id == \"xxx\") body += he.InnerHtml;\r\n            }\r\n            *\/\r\n\r\n            webBrowser1.Document.Body.InnerHtml = body;\r\n            isLoad = true;\r\n\r\n        }\r\n\r\n        private void timer1_Tick(object sender, EventArgs e)\r\n        {\r\n            this.Text = DateTime.Now.ToString();\r\n\r\n            if (isLoad == true &amp;&amp; DateTime.Now.Minute.ToString() == \"59\" &amp;&amp; DateTime.Now.Second.ToString() == \"59\") isLoad = false;\r\n            if (isLoad == false &amp;&amp; DateTime.Now.Minute.ToString() == \"1\" &amp;&amp; DateTime.Now.Second.ToString() == \"1\") webBrowser1.Refresh();\r\n\r\n        }\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u304cIE\u306b\u306a\u308b\u3088\u3046\u3067\u3001IE\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u5909\u66f4\u306f\u30ec\u30b8\u30b9\u30c8\u30ea\u304b\u3089\u306e\u307f\u3002 \u6bce\u56de\u3001DocumentCompleted\u304c\u8d70\u308b\u306e\u3067\u7121\u9650\u30eb\u30fc\u30d7\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u6ce8\u610f\u3002 using System; using Syste &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=1673\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# Web\u30b5\u30a4\u30c8\u8aad\u8fbc&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9],"class_list":["post-1673","post","type-post","status-publish","format-standard","hentry","category-1","tag-c-net"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/1673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1673"}],"version-history":[{"count":5,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/1673\/revisions"}],"predecessor-version":[{"id":1811,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/1673\/revisions\/1811"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}