ASP采集程序常用功能函数
'==================================================
'函数名:GetHttpPage
'作 用:获取网页源码
'参 数:HttpUrl ------网页地址
'==================================================
Function GetHttpPage(HttpUrl)
If IsNull(HttpUrl)=True Or Len(HttpUrl)<18 Or HttpUrl="$False$" Then
GetHttpPage="$False$"
Exit Function
End If
Dim Http
Set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",HttpUrl,False
Http.Send()
If Http.Readystate<>4 then
Set Http=Nothing
GetHttpPage="$False$"
Exit function
End if
GetHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
Set Http=Nothing
If Err.number<>0 then
Err.Clear
End If
End Function
'==================================================
'函数名:BytesToBstr
'作 用:将获取的源码转换为中文
'参 数:Body ------要转换的变量
'参 数:Cset ------要转换的类型
'==================================================
Function BytesToBstr(Bod ......
<%
'true=是邮件;false=不是;
Function validate(ByVal str)
Dim temp,reg
Set reg = new regexp
reg.ignorecase=true
reg.global=true
reg.pattern = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"
validate = reg.test(Trim(str))
Set reg = Nothing
End Function
'********************************************
'函数名:IsValidEmail
'作 用:检查Email地址合法性
'参 数:email ----要检查的Email地址
'返回值:True ----Email地址合法
' False ----Email地址不合法
'********************************************
function IsValidEmail(email)
dim names, name, i, c
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
......
对于大量的数据分页传统的asp分页方法(Rs.PageSize)存在很大的弊端:第一次打开页面时,它会预读所有的记录集,这当在数据大的时候,这将是致命的,翻页速度也会非常慢,非常占用资源。
我在操作大量程序的时候用Rs.PageSize方法分页经常出现程序运行超时错误,(数据量在几万左右程序优化不好的情况下经常出现程序运行超时),处理这种大量数据我使用的下面的方法暂时解决:
首先是记录打开时的游标类型,由于只是对记录进行顺序遍历所以我使用用rs.open sql,conn,0,1
0,1,这应是最快的游标类型了(详细)
adOpenForwardOnly 0 默认值。只支持向前顺序访问数据,如果只需要顺序遍历全部数据,该方法可以提供较高的执行性能
adLockReadOnly 1 只读方式,不能对数据进行修改
其次是每页只读出需要的记录,不预读所有的记录集
修改后的代码
<%
totalrec=0 '总记录数
msg_per_page=20 '每页显示记录数
currentpage=request.QueryString("page")'当前页码
n=0'总页数
if currentpage="" then currentpage=0
'取得总记录数
set rs=server.CreateObject ......
COM接口VC实现,接口:
[id(1), helpstring("method Test")] HRESULT Test([in] BSTR strInputA, [in] BSTR strInputB, [out,retval] VARIANT* result);
ASP调用:
Set objCompInfo =server.CreateObject("组件在系统中的名字")
result=objCompInfo.Test(arrIn,arrout)
"组件在系统中的名字" 该值在VC项目中的rgs文件中可以找到 ......
程序代码
public static string GetRealIP()
{
string ip;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
}
else
{
ip = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}
return ip;
}
获取代理IP
程序代码
public static string GetViaIP()
{
string viaIp = null;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
viaIp = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}
return viaIp;
} ......
程序代码
public static string GetRealIP()
{
string ip;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
}
else
{
ip = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}
return ip;
}
获取代理IP
程序代码
public static string GetViaIP()
{
string viaIp = null;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
viaIp = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}
return viaIp;
} ......
<% @ Page Language = " C# " %>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< script runat ="server" >
System.Data.DataView CreateDataSourceByXianhuiMeng()
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add( new System.Data.DataColumn( " id " , typeof (System.Int32)));
dt.Columns.Add( new System.Data.DataColumn( " 学生姓名 " , typeof (System.String)));
dt.Columns.Add( new System.Data.DataColumn( " 语文 " , typeof (System.Decimal)));
dt.Columns.Add( new System.Data.DataColumn( " 数学 " , typeof (System.Decimal)));
dt.Columns.Add( new System.Data.DataColumn( " 英语 " , typeof (Sy ......