最終結果
最終的には以下のようなソースコードになります。
using System;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace XboxNewGames
{
class Program
{
static void Main(string[] args)
{
var client = new WebClient { Encoding = Encoding.UTF8 };
var html = client.DownloadString("http://marketplace.xbox.com/ja-JP/Games/All?xr=shellnav");
var matches = Regex.Matches(html, @"/ja-JP/Pro[^""]*""\>(?<title>.*)\</a");
foreach (Match m in matches)
{
Console.WriteLine(m.Groups["title"].Value);
}
}
}
}
実行結果は以下の通りです。
GUI化してしまおうか
最後におまけでGUI化してしまいましょう。
見てのとおり、xbox.comからゲームタイトルを抽出する部分は文字ベース(コンソール)版からのコピペで作っています。残りの部分もほとんどVisual Studioの生成するテンプレートどおりで、追加したコードは数行だけになります。
<Window x:Class="XboxNewGamesGui.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox Name="List" />
</Grid>
</Window>
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
namespace XboxNewGamesGui
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var client = new WebClient { Encoding = Encoding.UTF8 };
var html = client.DownloadString("http://marketplace.xbox.com/ja-JP/Games/All?xr=shellnav");
var matches = Regex.Matches(html, @"/ja-JP/Pro[^""]*""\>(?<title>.*)\</a");
foreach (Match m in matches)
{
this.List.Items.Add(m.Groups["title"].Value);
}
}
}
}
完成形
![]() |
VBたん:
でも、最初に「完成形」として見せたやつと比べるとずいぶんしょぼくない? |
![]() |
C#たん:
完成形、解説しだすと長くなるのでソースコードだけ置いておきますね(΄◉◞౪◟◉‵)ニコッ |
![]() |
|
![]() |
ええ、使いますが何か?
ちなみに、CTPっていうのはCommunity Technology Previewの略で、わかりやすく言うと、ベータ版より前の、超人柱版のことです。 人柱ですが何か? |
![]() |
出てまだ数か月のCTP、日本語情報もろくにないものなんて、初心者どころか、並の開発者もコンパイルできないわよ。
さては、最初から解説する気なかったでしょ(笑) |





