c#用microsoft visual 2010做爬虫 现已能抓取url和所耗时间,但是抓取标题和京东价格还是失败的,这是期末作业,但是纯属自学,老师也没教过,求各位大神指导,还需要前台数据显示,我的数据库是用access的,暂时只存了抓取成功的url 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 做爬虫可不容易,但发现你说的像是做数据采集,你既然获取到了url,那直接获取url内容,从html中获取标题跟价格就行了。access一般够用了。前台数据显示要看你自己想法了,具体要做什么用就怎么显示 谁知道你是怎么写的呢?谁知道你在动手前预先了解和设计了什么逻辑方法了呢?很简单的东西,十分钟就做完了。前提是你要学会使用至少一种html语法分析,然后顺着这个思路去写代码。而不要去找错误的、混乱的方法。 获取的html中包括了标题和价格,用正则表达式获取。 private void WebExpress1(string s)//抓取网页标题 { string tag1 = "< title=" ; string tag2 = " >"; int pos1 = s.IndexOf(tag1); int pos2, pos3; while (pos1 > 0) { pos2 = s.IndexOf(tag2, pos1 + 1); if (pos2 < 0) return; pos3 = s.IndexOf(" ", pos1 + 10); if (pos3 > 0 && pos3 < pos2) pos2 = pos3; string data = s.Substring(pos1 + tag1.Length, pos2 - pos1 - tag1.Length); data = data.Replace(">", ""); data = data.Replace("\"", ""); int pos4 = data.IndexOf("title"); if (pos4 < 0) textBox4.Text += data + "\n"; s = s.Substring(pos2 + 1); pos1 = s.IndexOf(tag1); } }不知道哪里错了,无法成功 notnetbar10 有在郑州的么 如何把sql2005的数据库还原到sql2000?? 散分了!!! c#写的关于日期时间的查询语句 求救!!!未将对象引用设置到对象的实例。.... c#的桌面客户端,使用SQLite数据库靠谱吗 C#中读取文本文件,如何将数字字符串,转换成数字? 两个应用程序(exe文件),之间可以通过什么传递处理结果呢?? WinC#中有关正则表达式的操作 请问如何编译成多个DLL文件?! 代码简化问题 求一个算法
{
string tag1 = "< title=" ;
string tag2 = " >";
int pos1 = s.IndexOf(tag1);
int pos2, pos3;
while (pos1 > 0)
{
pos2 = s.IndexOf(tag2, pos1 + 1);
if (pos2 < 0)
return;
pos3 = s.IndexOf(" ", pos1 + 10);
if (pos3 > 0 && pos3 < pos2)
pos2 = pos3;
string data = s.Substring(pos1 + tag1.Length, pos2 - pos1 - tag1.Length);
data = data.Replace(">", "");
data = data.Replace("\"", "");
int pos4 = data.IndexOf("title");
if (pos4 < 0)
textBox4.Text += data + "\n";
s = s.Substring(pos2 + 1);
pos1 = s.IndexOf(tag1);
}
}
不知道哪里错了,无法成功