vfp9.0通过WebBrowser控件获取QQ新闻标题及链接
2011-11-04 16:48
302 查看
*!* by:十豆三
*!* vfp版本:vfp9.0
*!* 控件名称: Microsoft Web Browser(Microsoft Internet Controls)
*!* 控件版本:1.1
*!* ProgID:Shell.Explorer.2
*!* 文件位置: C:\WINDOWS\system32\ieframe.dll
*!* 文件版本:8.00.6001.19098 (IE8.0)
Public oform1
oform1=Newobject("form1")
oform1.Show
Return
Define Class form1 As Form
Top = 11
Left = 26
Height = 600
Width = 800
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
Add Object olecontrol1 As OleControl With ;
Top = 0, ;
Left = 0, ;
Height = 468, ;
Width = 800, ;
Name = "Olecontrol1", ;
OleClass = "Shell.Explorer.2", ;
OleLCID = 1033
Add Object command1 As CommandButton With ;
Top = 521, ;
Left = 677, ;
Height = 25, ;
Width = 121, ;
Caption = "取得新闻标题和URL", ;
Name = "Command1"
Add Object grid1 As Grid With ;
DeleteMark = .F., ;
Height = 129, ;
Left = 2, ;
ReadOnly = .T., ;
Top = 470, ;
Visible = .F., ;
Width = 673, ;
Name = "Grid1"
Procedure Load
_vfp.AutoYield=.F.
Endproc
Procedure Unload
_vfp.AutoYield=.T.
Endproc
Procedure olecontrol1.Init
This.Navigate("http://roll.news.qq.com/")
Endproc
Procedure command1.Click
lcMyCaption=This.Caption
This.Caption='正在获取......'
This.Enabled=.F.
Create Cursor T1 (类别 C(6),新闻标题 C(254),新闻链接 C(254),时间 C(11))
Thisform.Olecontrol1.Document.getElementById("auto_refresh").parentNode.className='check checked'
Thisform.Olecontrol1.Document.parentWindow.Execscript('AutoRefresh()') && 取消自动刷新
lnTotalPages=Val(Thisform.Olecontrol1.Document.getElementById("totalPage").Value) && 取得部页数
If Messagebox('共有'+Transform(lnTotalPages)+'页新闻,点<是>取得所有页的新闻,点击<否>只取当第1页的新闻。',4+32+256,'信息提示')=7
lnTotalPages=1
Endif
For m.lnJ=1 To lnTotalPages && 循环所有页,每页50条新闻,如果只需TOP N条,修改此处。
If m.lnJ>1
Thisform.Olecontrol1.Document.parentWindow.Execscript('nextPage()') && 下一页
Endif
Do While .T.
If Thisform.Olecontrol1.Document.getElementById("artContainer").innerhtml<>'<DIV class=loading>正在查询请稍候……</DIV>'
Exit
Endif
Inkey(0.2,"H") &&防止程序失去响应
Enddo
lcListStr=Thisform.Olecontrol1.Document.getElementById("artContainer").innerhtml && 取得当前页新闻内容
lnLIs=Occurs('<LI>',lcListStr)
For m.lnI=1 To lnLIs
Insert Into T1 Values (Strextract(lcListStr,'t-tit>','</SPAN><A',m.lnI),Strextract(lcListStr,'"undefined">','</A>',m.lnI),Strextract(lcListStr,'href="','" target',m.lnI),Strextract(lcListStr,'t-time>','</SPAN><SPAN',m.lnI))
Endfor
Endfor
Locate
Thisform.Grid1.RecordSource='T1'
Thisform.Grid1.Visible=.T.
Thisform.Grid1.AutoFit()
Thisform.Grid1.Refresh
This.Caption=lcMyCaption
This.Enabled=.T.
Messagebox('取得新闻信息完成!'+Chr(10)+Chr(10)+'共取得'+Transform(Reccount('T1'))+'条新闻',64,'信息提示')
Endproc
Procedure grid1.Scrolled
Lparameters nDirection
This.AutoFit()
Endproc
Enddefine
*!* vfp版本:vfp9.0
*!* 控件名称: Microsoft Web Browser(Microsoft Internet Controls)
*!* 控件版本:1.1
*!* ProgID:Shell.Explorer.2
*!* 文件位置: C:\WINDOWS\system32\ieframe.dll
*!* 文件版本:8.00.6001.19098 (IE8.0)
Public oform1
oform1=Newobject("form1")
oform1.Show
Return
Define Class form1 As Form
Top = 11
Left = 26
Height = 600
Width = 800
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
Add Object olecontrol1 As OleControl With ;
Top = 0, ;
Left = 0, ;
Height = 468, ;
Width = 800, ;
Name = "Olecontrol1", ;
OleClass = "Shell.Explorer.2", ;
OleLCID = 1033
Add Object command1 As CommandButton With ;
Top = 521, ;
Left = 677, ;
Height = 25, ;
Width = 121, ;
Caption = "取得新闻标题和URL", ;
Name = "Command1"
Add Object grid1 As Grid With ;
DeleteMark = .F., ;
Height = 129, ;
Left = 2, ;
ReadOnly = .T., ;
Top = 470, ;
Visible = .F., ;
Width = 673, ;
Name = "Grid1"
Procedure Load
_vfp.AutoYield=.F.
Endproc
Procedure Unload
_vfp.AutoYield=.T.
Endproc
Procedure olecontrol1.Init
This.Navigate("http://roll.news.qq.com/")
Endproc
Procedure command1.Click
lcMyCaption=This.Caption
This.Caption='正在获取......'
This.Enabled=.F.
Create Cursor T1 (类别 C(6),新闻标题 C(254),新闻链接 C(254),时间 C(11))
Thisform.Olecontrol1.Document.getElementById("auto_refresh").parentNode.className='check checked'
Thisform.Olecontrol1.Document.parentWindow.Execscript('AutoRefresh()') && 取消自动刷新
lnTotalPages=Val(Thisform.Olecontrol1.Document.getElementById("totalPage").Value) && 取得部页数
If Messagebox('共有'+Transform(lnTotalPages)+'页新闻,点<是>取得所有页的新闻,点击<否>只取当第1页的新闻。',4+32+256,'信息提示')=7
lnTotalPages=1
Endif
For m.lnJ=1 To lnTotalPages && 循环所有页,每页50条新闻,如果只需TOP N条,修改此处。
If m.lnJ>1
Thisform.Olecontrol1.Document.parentWindow.Execscript('nextPage()') && 下一页
Endif
Do While .T.
If Thisform.Olecontrol1.Document.getElementById("artContainer").innerhtml<>'<DIV class=loading>正在查询请稍候……</DIV>'
Exit
Endif
Inkey(0.2,"H") &&防止程序失去响应
Enddo
lcListStr=Thisform.Olecontrol1.Document.getElementById("artContainer").innerhtml && 取得当前页新闻内容
lnLIs=Occurs('<LI>',lcListStr)
For m.lnI=1 To lnLIs
Insert Into T1 Values (Strextract(lcListStr,'t-tit>','</SPAN><A',m.lnI),Strextract(lcListStr,'"undefined">','</A>',m.lnI),Strextract(lcListStr,'href="','" target',m.lnI),Strextract(lcListStr,'t-time>','</SPAN><SPAN',m.lnI))
Endfor
Endfor
Locate
Thisform.Grid1.RecordSource='T1'
Thisform.Grid1.Visible=.T.
Thisform.Grid1.AutoFit()
Thisform.Grid1.Refresh
This.Caption=lcMyCaption
This.Enabled=.T.
Messagebox('取得新闻信息完成!'+Chr(10)+Chr(10)+'共取得'+Transform(Reccount('T1'))+'条新闻',64,'信息提示')
Endproc
Procedure grid1.Scrolled
Lparameters nDirection
This.AutoFit()
Endproc
Enddefine
相关文章推荐
- vfp9.0通过WebBrowser控件获取QQ新闻标题及链接
- WIN API-VFP获取第三方窗体的控件信息(句柄,窗口ID,进程ID,类名,标题
- CHtmlView 和 Webbrowser 控件中超链接点击事件的获取与检测
- VB.NET 通过窗口句柄,获取webbrowser控件HTML内容
- 【C#】通过webbrowser控件自动注册QQ号讲解
- c#中获取webbrowser控件加载页面中的链接的地址
- CHtmlView 和 Webbrowser 控件中超链接点击事件的获取与检测
- CHtmlView 和 Webbrowser 控件中超链接点击事件的获取与检测
- 【C#】通过webbrowser控件获取验证码
- python3 bs4 requests 腾讯新闻 标题 链接获取 小试牛刀
- 通过webbrowser控件获取验证码
- WIN API-VFP获取第三方窗体的控件信息(句柄,窗口ID,进程ID,类名,标题)
- CHtmlView 和 Webbrowser 控件中超链接点击事件的获取与检测
- CHtmlView 和 Webbrowser 控件中超链接点击事件的获取与检测
- 网络采集软件核心技术剖析系列(1)---如何使用C#语言获取博客园某个博主的全部随笔链接及标题
- 获取网页中的部分内容,新闻标题和内容
- 浅析Page.LoadTemplate("模板")方法动态获取绑定模板后,通过FindControl获取服务端控件的方法。
- 获取IE (控件)的所有链接(包括Frameset, iframe)
- gridview绑定checkbox控件后,通过单击CheckedChanged事件获取当前选择行的数据
- 怎样通过HOOK获取QQ登录密码