28,391
社区成员
发帖
与我相关
我的任务
分享
Sub Demo1()
arrUrl=""&_
"http://cn.mouser.com/Search/Refine.aspx?N=1323043&Keyword=ATSAM&FS=True"&vbcrlf&_
"http://cn.mouser.com/Search/Refine.aspx?N=1323043&Keyword=ATSAM&No=25&FS=True"&vbcrlf&_
"http://cn.mouser.com/Search/Refine.aspx?N=1323043&Keyword=ATSAM&No=50&FS=True"&vbcrlf&_
"http://cn.mouser.com/Search/Refine.aspx?N=1323043&Keyword=ATSAM&No=75&FS=True"
Response.Write("<div style='height:500px; width:1000px; overflow:scroll; padding:15px;border:2px solid #ccc'>")
arrUrl=Split(arrUrl,vbcrlf)
Set http=New jm_ClsThief
http.Charset="utf-8"
For i=0 To uBound(arrUrl)
url=arrUrl(i)
Response.Write("第"&i+1&"页 <a href='"&url&"' target=_blank>"&url&"</a><br>")
content=http.GetBody(url)
content=http.Cut(content,"<tr class=""SearchResultsRowOdd"">","<!--- Search Tips --->","[@")
Mouser_Page()
Next
Response.Write("</div>")
End Sub
Sub Demo2()
Response.Write("<div style='height:500px; width:1000px; overflow:scroll; padding:15px;border:2px solid red'><h1 style=color:red>Demo2 这里面测试有问题,说页面不存在,只有第一页能正常采集,其他页采集不到,通过第一页获取总页数,然后遍历种个分页,循环采集</h1>")
url="http://cn.mouser.com/Search/Refine.aspx?N=1323043&Keyword=ATSAM&FS=True"
Set http=New jm_ClsThief
http.Charset="utf-8"
http.IsDebug=true
content=http.GetBody(url)
content=http.Cut(content,"<tr class=""SearchResultsRowOdd"">","<!--- Search Tips --->","[@")
'取搜索数据总页数及网址
arrData=http.GetArray("href=""[^>]+"">(\d+)<\/a><a id=""ctl00_ContentMain_PagerBottom_lnkNext"" href=""([^>]+)"">下一页",content,0,1)
If http.Found Then
flag=http.Found : page=Trim(arrData(0,0)) : pageUrl="http://cn.mouser.com"&unescape(Rtrim(arrData(0,1)))
Response.Write("<h5>共"&page&"页 "&pageUrl&"</h5>")
End If
Response.Write("第1页 <a href='"&url&"' target=_blank>"&url&"</a><br>")
Mouser_Page()
If flag Then
For i=2 To Page
j=i-1
pageUrl=RegReplace("No=\d+",pageUrl,"No="&j*25,1,1)
Response.Write("第"&i&"页 <a href='"&pageUrl&"' target=_blank>"&pageUrl&"</a><br>")
content=http.GetBody(pageUrl)
If content<>"<!--null-->" Then
content=http.Cut(content,"<tr class=""SearchResultsRowOdd"">","<!--- Search Tips --->","[@")
Mouser_Page()
End If
Next
End If
Response.Write("</div>")
End Sub