试了一下338页也不用多少时间。
程序代码:
程序代码:
DECLARE long URLDownloadToFileA IN urlmon long,string,string,long,long
DECLARE long DeleteUrlCacheEntry IN wininet string
DECLARE long malloc IN msvcrt long
DECLARE long free IN msvcrt as _free long
DECLARE long strcpy IN msvcrt long,string
DECLARE long strstr IN msvcrt long,string
CREATE TABLE vfplt (序号 N(8), 主题 C(240), 发表 C(20), 回复 C(6), 人气 C(8), 最后更新 C(30))
n序号 = 0
FOR i=1 TO 338
url = "https://bbs.bc-/forum-22-" + TRANSFORM(i) + ".html"
getPageData(getHtml(url))
?? url + 0h0D
ENDFOR
SELECT * FROM vfplt
CLEAR ALL
RETURN
FUNCTION getPageData(cHtml)
LOCAL pHtml, p
pHtml = _malloc(LEN(cHtml)+1)
IF pHtml == 0
RETURN
ENDIF
strcpy(pHtml, cHtml)
p = pHtml
DO WHILE p > 0
getTextByTagName(@p, [<td class="title">], [</td>])
getTextByTagName(@p, [<a], [</a>])
c主题 = getTextByTagName(@p, [>], [</a>])
getTextByTagName(@p, [<td class="l_au">], [</td>])
getTextByTagName(@p, [<a], [</a>])
c发表 = getTextByTagName(@p, [>], [</a>])
c回复 = getTextByTagName(@p, [<td class="l_re">], [</td>])
c人气 = getTextByTagName(@p, [<td class="l_re">], [</td>])
getTextByTagName(@p, [<td class="l_last">], [</td>])
getTextByTagName(@p, [<a], [</a>])
c最后更新 = getTextByTagName(@p, [>], [</a>])
getTextByTagName(@p, [<a], [</a>])
c最后更新 = c最后更新 + " " + getTextByTagName(@p, [>], [</a>])
IF !EMPTY(c主题)
n序号 = n序号 + 1
INSERT INTO vfplt VALUES (n序号, c主题, c发表, c回复, c人气, c最后更新)
ENDIF
ENDDO
_free(pHtml)
ENDFUNC
FUNCTION getTextByTagName(p, cBeginTagName, cEndTagName)
IF p == 0
RETURN ""
ENDIF
p = strstr(p, cBeginTagName)
IF p == 0
RETURN ""
ENDIF
p = p + LEN(cBeginTagName)
LOCAL p2
p2 = strstr(p, cEndTagName)
IF p2 == 0
RETURN ""
ENDIF
RETURN SYS(2600, p, p2-p)
ENDFUNC
FUNCTION getHtml(url)
LOCAL tmpHtml
tmpHtml = "C:\_temp\bccn_vfp.html" && 临时文件要用自己的路径
DeleteUrlCacheEntry(url)
IF URLDownloadToFileA(0, url, tmpHtml, 0, 0)==0
RETURN FILETOSTR(tmpHtml)
ENDIF
? "下载 " + url + " 失败"
RETURN ""
ENDFUNC
FUNCTION _malloc(nSize)
LOCAL ptr
ptr = malloc(nSize)
IF ptr == 0
? "执行malloc()分配内存失败"
ENDIF
RETURN ptr
ENDFUNC
[此贴子已经被作者于2025-11-14 20:37编辑过]







