111,119
社区成员
发帖
与我相关
我的任务
分享
textBox3.Text += item + "\r\n";
//regex=Regex.Match(pageHtml,strregex).ToString();
foreach (var item in Regex.Matches(pageHtml,strregex))
{
textBox3.Text = item.ToString() + "\r\n";
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace FormMain
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDefine_Click(object sender, EventArgs e)
{
int one=Convert.ToInt32(textBox1.Text);
int tow=Convert.ToInt32(textBox2.Text);
WebClient webrespen = new WebClient();
webrespen.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。
byte[] pagedata = null;//用于获取指定的链接
string pageHtml = string.Empty;//接受解码后的数据
string strregex = "\\bhttp://www\\.amazon.cn/mn/detailApp/ref=sr_1_\\d+\\?_encoding=UTF8&s=books&qid=\\d+&asin=\\w+&sr=1-\\d+\\b";
string regex=string.Empty;
for (int i = one; i <=tow; i++)
{
string strurl = "http://www.amazon.cn/s/ref=?ie=UTF8&n=658490051&page=" + i.ToString();
pagedata = webrespen.DownloadData(strurl);//从指定网站下载数据
pageHtml = Encoding.UTF8.GetString(pagedata);//如果获取网站页面采用的是UTF-8,则使用这句
regex=Regex.Match(pageHtml,strregex).ToString();
foreach (string item in regex )
{
textBox3.Text = item + "\r\n";
}
}
}
}
}
foreach (string link in links)
{
TextBox1.Text += link + "\r\n";
}