2,723
社区成员
发帖
与我相关
我的任务
分享
cUrl = 'www.smm.cn'
oForm = NewObject('form')
oForm.AddObject('wb1','olecontrol','Shell.Explorer.2')
oForm.wb1.Visible = .t.
oForm.wb1.navigate(cUrl)
Wait window nowait noclear '正在加载网页 ... ' + cUrl
Do while IsNull(oForm.wb1.Document)
Inkey(0.1)
EndDo
Do while IsNull(oForm.wb1.Document.body)
Inkey(0.1)
EndDo
Do while IsNull(oForm.wb1.Document.getElementById('tabs-1'))
Inkey(0.1)
EndDo
Wait clear
Create Cursor ttt (f1 N(3), f2 V(20), f3 V(20), f4 V(20), f5 V(20), f6 V(20))
ot = oForm.wb1.Document.getElementById('tabs-1').firstElementChild.firstElementChild
ii = 0
For each o1 in ot.children
Append Blank
Replace next 1 f1 with ii
jj = 1
For each o2 in o1.children
jj = jj + 1
ff = Textmerge('f<<jj>>')
If !Empty(Field(ff))
Replace next 1 (ff) with o2.innerText
EndIf
EndFor
ii = ii + 1
EndFor
Store Null to ot, oForm
Locate
Browse
Local oHttp, cc, cc1, ii
oHttp = NewObject('Microsoft.XMLHttp')
oHttp.open('GET', 'http://www.smm.cn/', .f.)
oHttp.send()
Do while oHttp.readyState <> 4
Inkey(0.1)
EndDo
cc = '' + oHttp.responseBody
oHttp = Null
cc = StrExtract(cc, '<div class="tl-price" id="tabs-1">','</table>', 1, 4)
Do while !Empty(StrExtract(cc, '<!--', '-->')) && 去掉 html 注释行
cc = Strtran(cc, StrExtract(cc, '<!--', '-->', 1, 4), '')
EndDo
*-- html 源码空格不规范,干脆都去掉, tr 标签不统一补全一下, 以便后续处理
cc = Chrtran(cc, Space(1), '')
cc = Strtran(cc, '<tr>', '<trclass="">')
Create Cursor ttt (no I, name V(20), price V(20), aver V(10), change V(10), date V(10))
For ii = 2 to Occurs('<trclass="', cc)
cc1 = StrExtract(cc, '<trclass="', '</tr>', ii, 4)
Append Blank
Replace next 1 ;
no With ii - 1 ;
, name With trimtags(Strextract(cc1, '<tdclass="name"', '</td>', 1, 4)) ;
, price With trimtags(Strextract(cc1, '<tdclass="price"', '</td>', 1, 4)) ;
, aver With trimtags(Strextract(cc1, '<tdclass="aver"', '</td>', 1, 4)) ;
, change With trimtags(Strextract(cc1, '<tdclass="change"', '</td>', 1, 4)) ;
, date With trimtags(Evl(Strextract(cc1, '<tdclass="date"', '</td>', 1, 4) ;
, Strextract(cc1, '<tdclass="today"', '</td>', 1, 4)))
EndFor
Locate
Browse
Function trimtags(tcDesc as String)
Local ii
For ii = Occurs('<', tcDesc) to 1 step -1
tcDesc = Strtran(tcDesc, StrExtract(tcDesc, '<', '>', ii, 2+4), '')
EndFor
Return tcDesc
EndFunc
Local oHttp, cc, cc1, ii
oHttp = NewObject('Microsoft.XMLHttp')
oHttp.open('GET', 'http://www.smm.cn/', .f.)
oHttp.send()
Do while oHttp.readyState <> 4
Inkey(0.1)
EndDo
cc = '' + oHttp.responseBody
oHttp = Null
cc = StrExtract(cc, '<div class="tl-price" id="tabs-1">','</table>', 1, 4)
Do while !Empty(StrExtract(cc, '<!--', '-->')) && 去掉 html 注释行
cc = Strtran(cc, StrExtract(cc, '<!--', '-->', 1, 4), '')
EndDo
cc = Chrtran(cc, Space(1), '') && 源码空格不规范,干脆全部去掉
Create Cursor ttt (no I, name V(20), price V(20), aver V(10), change V(10), today V(10))
For ii = 2 to Occurs('<tr', cc)
cc1 = StrExtract(cc, '<tr', '</tr>', ii, 4)
Append Blank
Replace next 1 no with ii - 1
Replace next 1 name with trimtags(StrExtract(cc1, '<tdclass="name"', '</td>', 1, 4))
Replace next 1 ;
price with StrExtract(cc1, '<tdclass="price">', '</td>', 1) ;
, aver with StrExtract(cc1, '<tdclass="aver">', '</td>', 1) ;
, change with StrExtract(cc1, '<tdclass="change">', '</td>', 1) ;
, today with StrExtract(cc1, '<tdclass="today">', '</td>', 1)
EndFor
Locate
Browse
Function trimtags(tcDesc as String)
Local ii
For ii = Occurs('<', tcDesc) to 1 step -1
tcDesc = Strtran(tcDesc, StrExtract(tcDesc, '<', '>', ii, 2+4), '')
EndFor
Return tcDesc
EndFunc