xamarin.android(Visual Studio)を用いて
ヤフーのhtmlから<title>タグの中の「Yahoo! JAPAN」を抜き出そうとしているのですが、
エミュレータではうまく取得、表示できてもても、
実機では「問題が発生しました」とエラーをはいて出来ません。
すごくざっくりと聞きますが、どのようすれば解決するか教えてください。
c#
1using System; 2using Android.App; 3using Android.Widget; 4using Android.OS; 5using hap = HtmlAgilityPack; 6using System.Linq; 7 8 9namespace App1 10{ 11 [Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")] 12 public class MainActivity : Activity 13 { 14 protected override void OnCreate(Bundle bundle) 15 { 16 base.OnCreate(bundle); 17 18 // Set our view from the "main" layout resource 19 SetContentView(Resource.Layout.Main); 20 21 // Get our button from the layout resource, 22 // and attach an event to it 23 Button button = FindViewById<Button>(Resource.Id.MyButton); 24 25 button.Click += delegate { 26 27 string url = "http://www.yahoo.co.jp/"; 28 29 System.Net.WebClient web = new System.Net.WebClient(); 30 string htmlSource = web.DownloadString(url); 31 hap.HtmlDocument html = new hap.HtmlDocument(); 32 html.LoadHtml(htmlSource); 33 var tags = html.DocumentNode.Descendants("title").Last().InnerText; 34 35 button.Text = tags; 36 }; 37 } 38 } 39}
動作環境等
・xamarin.android(Visual Studio 2015)
・API19
・android4.4
・実機(sharp sh-01F)
・HtmlAgilityPack利用
回答2件
あなたの回答
tips
プレビュー