淘宝要得到这个商品的,价格,名字。销量..
帮忙来个正则吧。淘宝要得到这个商品的,价格,名字。销量..帮忙来个正则吧。淘宝要得到这个商品的,价格,名字。销量..
帮忙来个正则吧。淘宝要得到这个商品的,价格,名字。销量..
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.open("GET", "http://detail.tmall.com/item.htm?id=13620534478", False)
$oHTTP.send()
$source1 = $oHTTP.responsetext
Local $aTitle,$sTitle = ""
$aTitle = StringRegExp($source1,'name="title"\s*value="(.*?)"',3)
If Not @error Then $sTitle = $aTitle
Local $aPrice,$iPrice = ""
$aPrice = StringRegExp($source1,'"J_StrPrice"\s*>(\d+\.\d+).*元',3)
If Not @error Then $iPrice = $aPrice
Local $aSales,$iSales = ""
$aSales = StringRegExp($source1,'(?i)月\s销\s量:</SPAN><EM>(\d*)</EM>件',3)
If Not @error Then $iSales = $aSales
MsgBox(0,"","商品名称:" & $sTitle & @CRLF & "价格:" & $iPrice & @CRLF & "月销量:" & $iSales) 居然这么廉价,才10块论坛币。还是不看了 本帖最后由 suiyefeng 于 2012-7-22 07:25 编辑
#include <WinHttp_GetRespond.au3>
$url = "http://detail.tmall.com/item.htm?id=13620534478"
$list = SellCount($url)
MsgBox(64,"月销量",$list)
Func SellCount($url)
$rContext = _WinHTTP_GetRespond(-1, $url, 4 + 2, 10000)
If @error Then
Return -1
EndIf
;获取含有销量的网址
$initapi = StringRegExp($rContext, '"initApi" :.*"(.*?)"', 3)
If Not IsArray($initapi) Then
Return -2
EndIf
;获取销量
$rContext = _WinHTTP_GetRespond(-1, $initapi, 4 + 2, 10000)
If @error Then
Return -3
EndIf
$count = StringRegExp(BinaryToString($rContext), '"sellCount":(\d*)', 3)
If IsArray($count) Then
Return $count
Else
Return -4
EndIf
EndFunc
回复 3# suiyefeng
有时候得到销量= -1. 不标准。。
我在摸索一下 本帖最后由 suiyefeng 于 2012-7-22 07:33 编辑
汗 .....
改了点..你看返回的是的多少就知道问题出在哪了..剩下的你自己弄把{:face (394):} 淘宝开放平台,什么数据都能得到。 代码我已经写好! #include <IE.au3>
#include<guiconstantsex.au3>
#include<file.au3>
#include<windowsconstants.au3>
GUICreate("IE", 500, 480)
Global $gccal = GUICtrlCreateInput("", 10, 340, 440, 30)
Global $gccal2 = GUICtrlCreateInput("", 10, 380, 440, 30)
Global $gccal3 = GUICtrlCreateInput("", 10, 420, 440, 30)
_IEErrorHandlerRegister()
$oie = _IECreateEmbedded()
Local $obj = GUICtrlCreateObj($oie, 10, 10, 490, 290)
GUISetState()
GUIRegisterMsg($WM_SYSCOMMAND, "wm_syscommand")
Global $url = "http://detail.tmall.com/item.htm?id=13620534478"
test($url)
While 1
Local $msg = GUIGetMsg()
Select
Case $msg = -3
Exit
EndSelect
Sleep(1000)
WEnd
Func test($url)
Local $html = _IENavigate($oie, $url)
_IEAction($oie, "refresh")
_IELoadWait($oie)
Local $html3 = _IEBodyReadHTML($oie)
$hw = FileOpen(@DesktopDir & "\1.txt", 10)
FileWrite($hw, "")
FileWriteLine(@DesktopDir & "\1.txt", $html3)
Local $strarray
_FileReadToArray(@DesktopDir & "\1.txt", $strarray)
FileClose($hw)
FileDelete(@DesktopDir & "\1.txt")
GUICtrlSetData($gccal, "")
For $i = 238 To $strarray
Local $strmid = StringRegExp($strarray[$i], "举报此商品", 3)
If Not @error Then; 名称
Local $Strname = StringRegExp($strarray[$i - 1], 'target=_blank>([^\/]+?)</A>', 3) ;获取名称
If Not @error Then
GUICtrlSetData($gccal, "商品名称:" & $Strname)
EndIf
EndIf
Local $Sreg = StringRegExp($strarray[$i], 'Price>(\d+\.\d+)</STRONG>.*什么是专柜价', 3) ;获取价格
If Not @error Then
GUICtrlSetData($gccal2, "价格:" & $Sreg & " 元")
EndIf
Local $Srtmo = StringRegExp($strarray[$i], '.*月销量.+Num>(\d+)</EM>', 3) ;获取销量
If Not @error Then
GUICtrlSetData($gccal3, "月销量:" & $Srtmo & " 件")
ExitLoop
EndIf
Next
EndFunc ;==>test
Func wm_syscommand($hWnd, $sMsg, $sWParam, $slParam)
Switch $sWParam
Case 61536
Exit
EndSwitch
EndFunc ;==>wm_syscommand
页:
[1]