private void Form1_Load(object sender, EventArgs e) { string sURL; var sCategory = new string[1024]; var scr = new SampleScraping(); sURL = "https://www.amazon.co.jp/gp/site-directory?ref_=nav_em_T1_0_2_2_20__fullstore"; string sHtml = scr.GetHtml(sURL); GetCategory(sHtml, sCategory); dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; dataGridView1.RowHeadersWidth = 40; // カラム数を指定 //dataGridView1.ColumnCount = 4; // カラムのサイズ指定 dataGridView1.Columns[0].Width = 400; //商品名 dataGridView1.Columns[1].Width = 100; //価格(\) dataGridView1.Columns[2].Width = 100; //画像 dataGridView1.Columns[3].Width = 500; //商品URL dataGridView1.RowTemplate.Height = 60; dataGridView1.Columns[1].DefaultCellStyle.Format = "c"; dataGridView1.Columns[2].DefaultCellStyle.NullValue = null; }
private void button_search_Click(object sender, EventArgs e) { string sURL_Category, sURL_Item, sURL; string sPrice; var sCategory = new string[1024]; var scr = new SampleScraping(); sURL_Category = "http://www.amazon.co.jp/gp/search/?__mk_ja_JP=%83J%83%5E%83J%83i&url=search-alias%3D"; sURL_Item = "&field-keywords="; if (checkBox_price.Checked == true) { if (!PriceCheck()) { return; } else { sPrice = "&low-price=" + Convert.ToInt32(textBox_price_low.Text) + "&high-price=" + Convert.ToInt32(textBox_price_high.Text); } } else { sPrice = ""; } sURL = sURL_Category + comboBox_alias1.Text + sURL_Item + textBox_keyword.Text + sPrice + "&emi=AN1VRQENFRJN5"; //System.Diagnostics.Process.Start(sURL); string sHtml = scr.GetHtml(sURL); int next, tail; string work; dataGridView1.Rows.Clear(); while (true) { if (!SetDataToGrid(sHtml)) { break; } next = sHtml.IndexOf("<li class=\"a-last\"><a href=\""); if (next == -1) { break; } else { tail = sHtml.IndexOf(">次へ"); work = System.Web.HttpUtility.UrlDecode(sHtml.Substring(next + 28, tail - next - 29)); } sHtml = scr.GetHtml("https://amazon.co.jp" + work); } }