以下是引用nbwww在2021-8-30 13:37:08的发言:
可以打开的 有IP限止?
可以打开的 有IP限止?
可能是,换IP就好了。
不用浏览器打开时,好象要网页的cookie才能正常获取网页
程序代码:
cUrl = "https:///project/buildtablelist/938d3183-00f9-eb11-8e8f-005056b8d0cb" nPageCount = 0 cookie = GetUrlCookie(cUrl, @nPageCount) IF nPageCount == 0 RETURN ENDIF ? "共 "+TRANSFORM(nPageCount)+" 页" CREATE CURSOR tt (楼栋 C(50),房号 C(4),套内面积 c(10),建筑面积 c(10),; 所在层 C(2),规划用途 C(4),备案总价 C(12),户型 C(12),销售状态 C(8)) FOR i=1 TO nPageCount cTxt = UrlDownload(cUrl+"?page="+TRANSFORM(i), cookie) ? "第 "+TRANSFORM(i)+" 页"+IIF(!EMPTY(cTxt), " 成 功"," 失 败") IF !EMPTY(cTxt) GetTable(cTxt) ENDIF INKEY(1) && 要延时 ENDFOR SELECT * FROM tt RETURN FUNCTION GetUrlCookie(cUrl, nPageCount) LOCAL ie, cTxt ie = CREATEOBJECT("internetexplorer.application") ie.Navigate(cUrl) DO WHILE ie.Busy OR ie.ReadyState!=4 INKEY(1) ?? " 请稍候......",TIME()+0h0D ENDDO IF VARTYPE(ie.document)!="O" RETURN "" ENDIF cTxt = ie.document.body.innerHTML nPageCount = VAL(STREXTRACT(cTxt, [page=], [">尾页], OCCURS("page=",cTxt))) RETURN ie.document.cookie ENDFUNC FUNCTION UrlDownload(cUrl, Cookie) LOCAL wh wh = CREATEOBJECT("WinHttp.WinHttpRequest.5.1") wh.Open("GET", cUrl, 0) wh.SetRequestHeader("Cookie", Cookie) wh.Send() IF wh.status==200 RETURN STREXTRACT(wh.ResponseText,[<tbody>],[</tbody>]) ENDIF RETURN "" ENDFUNC FUNCTION GetTable(cTxt) LOCAL i,tr FOR i =1 TO OCCURS("<tr>",cTxt) tr = STREXTRACT(cTxt, [<tr>], [</tr>], i) INSERT INTO tt VALUES (; ALLTRIM(STREXTRACT(tr, [>], [<], 1), 0h20,0h0D,0h0A),; ALLTRIM(STREXTRACT(tr, [>], [<], 3), 0h20,0h0D,0h0A),; ALLTRIM(STREXTRACT(tr, [>], [<], 5), 0h20,0h0D,0h0A),; ALLTRIM(STREXTRACT(tr, [>], [<], 7), 0h20,0h0D,0h0A),; ALLTRIM(STREXTRACT(tr, [>], [<], 9), 0h20,0h0D,0h0A),; ALLTRIM(STREXTRACT(tr, [>], [<], 11), 0h20,0h0D,0h0A),; ALLTRIM(STREXTRACT(tr, [>], [<], 13), 0h20,0h0D,0h0A),; ALLTRIM(STREXTRACT(tr, [>], [<], 15), 0h20,0h0D,0h0A),; ALLTRIM(STREXTRACT(tr, [>], [<], 17), 0h20,0h0D,0h0A)) ENDFOR ENDFUNC