conan

导航

工作,工作。

   2005年4月4日   星期一   睛  河南郑州

  很长时间没有写随笔了,这两个月在为了工作奔波。在一个星期前我在广州呆了一个月,想想和去年七月份到广州的感受不同。去年我坐飞机到深圳后到中山又在广州白去区住了一个星期。当时对广州没什么太深的印象,就觉的广州城市规划的不太好,还没郑州强。可这次我在天河区的经历使我看到广州繁荣的一面,感触很深。

  电信大楼,广州体育中心,天河城,天河购书中心,在广州住过的人对这几个名字

               2005年4月7日   星期四   睛  河南郑州

         现在忙的一个随笔也要分两半写呀。我用十天写了一个从阿里巴巴大量提取产品信息的程序,昨天刚完成,是用c#做的。
我还是先书接上文说我在广州的见闻吧,呵呵。
. . . . . .
不,还是算了,免的有人说我没见是世面。


  我先将提取网页数据的核心代码放上,供大家参考。这个类实际是我用asp小偷程序换过来的。不过也有它的局限性,我在用时常遇到出现“错误:连接已超时”,还常遇到取出的字符串是""串的问题。因为本人能力有限,希望大家能改进一下。

using System;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Text;
using Microsoft.VisualBasic;
using System.IO;
using System.Net;
using System.Data.Common;
using System.Data.SqlClient;

namespace pq7798
{
    
/**//// <summary>
    
/// dataHelper 的摘要说明。
    
/// </summary>

    public class GetHttp
    
{
public static string Get_Http(string a_strUrl,int N,string EndStr)
        
{
            
string strResult;
            HttpWebRequest myReq 
= (HttpWebRequest)WebRequest.Create(a_strUrl) ;
            
    if(Referer!=null)
                myReq.Referer
=Referer;
            
try
            
{
                HttpWebResponse HttpWResp 
= (HttpWebResponse)myReq.GetResponse();
                Stream myStream 
= HttpWResp.GetResponseStream () ;

                StreamReader sr 
= new StreamReader(myStream , Encoding.Default);
                StringBuilder strBuilder 
= new StringBuilder();
                
int i=1;

                
while (-1 != sr.Peek())
                
{
                    
if(i<N)
                    
{
                        sr.ReadLine();
                        i
++;
                    }

                    
else
                    
{
                        
if(Strings.InStr(strBuilder.ToString(),EndStr,0)>0)
                            
break;
                        
else
                            strBuilder.Append(sr.ReadLine().Replace(
"width=","").Replace("align=center","").Replace("\t","").Replace("</a>",""));            //这里可以加上"\r\n"换行符
                    }

                }

                strResult 
= strBuilder.ToString();
            }

            
catch(Exception exp)
            
{
                strResult 
= "错误:" + exp.Message ;
                
//this.richTextBox1.Text=a_strUrl+"找不到";
            }

            
return strResult ;
          }

    }

}

posted on 2005-04-04 19:14  Conan  阅读(636)  评论(0编辑  收藏  举报