|
发表于 2011-11-16 13:47:13
|
显示全部楼层
写了几个函数可以实现
;查询主流价格
Func SearchItemPrice($word)
Local $aryv[2]
Local $gryup=AnsiURLEncode($word)
$res=InetGet("http://s.etao.com/search?q="&$gryup&"&sort=sale-desc",@TempDir&"\112233.txt",1+2+4+8+16)
InetClose($res)
Local $filenr=FileRead(@TempDir&"\112233.txt")
Local $seller=QUZJDX($filenr,'<div class="seller-name">','</div>')
Local $price=StringReplace(QUZJDX($filenr,'<li class="price">','</em>'),"<em>","")
$price223=StringRegExp($price,"(\d+\.\d{2})",3)
If UBound($price223)>0 Then $price=$price223[0]
If StringInStr($seller,'charset="gbk"')>0 Then
$aryv[0]="互联网"
Else
$aryv[0]=$seller
EndIf
If Not StringRegExp($price,"\d+\.\d{2}") Then
$aryv[0]="没有找到"
$aryv[1]="没有找到"
Else
$aryv[1]="¥"&$price
EndIf
If StringInStr($filenr,"抱歉, 没有找到")>0 Then
$aryv[0]="没有找到"
$aryv[1]="没有找到"
EndIf
Return $aryv
EndFunc
;截取项目中间的字符串
Func QUZJDX($stringc,$sstring,$estring,$cs=1)
Local $start=StringInStr($stringc,$sstring,1,$cs)+StringLen($sstring)
Local $end=StringInStr($stringc,$estring,0,1,$start)
If $end-$start<=0 Then Return ""
Return StringStripWS(StringMid($stringc,$start,$end-$start),3)
EndFunc
;转换UTF编码
Func AnsiURLEncode($str, $falg = 0)
;可选参数$falg = 0,不转换字母及数字(默认);$falg = 1,全部转换(字符头http://除外)
Local $str_s = StringRegExpReplace($str, '^(http://).+', '$1')
If @extended = 0 Then $str_s = ''
If @extended > 0 Then $str = StringRegExpReplace($str, '^http://', '')
Local $astr, $i, $s2d, $sS = StringSplit($str, '')
For $i = 1 To UBound($sS) - 1
If StringRegExp($sS[$i], '[^\x00-\xff]') Then
$s2d = StringToBinary($sS[$i] & ' ')
$astr &= '%' & StringMid($s2d, 3, 2) & '%' & StringMid($s2d, 5, 2)
ElseIf StringRegExp($sS[$i], '[^\w]') Then
$s2d = StringToBinary($sS[$i])
$astr &= '%' & StringMid($s2d, 3, 2)
Else
If $falg = 0 Then $astr &= $sS[$i]
If $falg <> 0 Then
$s2d = StringToBinary($sS[$i])
$astr &= '%' & StringMid($s2d, 3, 2)
EndIf
EndIf
Next
$astr = StringReplace($astr, '%20', '+') ;转换空格的编码为'+'号,也可不要此行
Return $str_s & $astr
EndFunc |
|