ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: 蓝天630902

[分享] 第一辑、网页:点击标签,翻页

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2012-5-31 07:07 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖已被收录到知识树中,索引项:网页交互
多谢分享,太牛了。。。。

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-5-31 11:42 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 蓝天630902 于 2012-6-1 13:54 编辑

一劳永逸地把所以标签全查一遍,
查找标签:

查找标签.rar

18.41 KB, 下载次数: 2027

评分

2

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-5-31 12:00 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
为了让没有注册本论坛的兄弟们方便,还是把代码贴出来:

Sub 查找标签innerText()
    Dim arr
    [a1:cm1] = Split("标签号,a,abbr,acronym,address,applet,area,b,base,basefont,bdo,big,blockquote,body,br,button,caption,center,cite,code,col,colgroup,dd,del,dfn,dir,div,dl,dt,em,fieldset,font,form,frame,frameset,head,h1,h2,h3,h4,h5,h6,hr,html,i,iframe,img,input,ins,kbd,label,legend,li,link,map,menu,meta,noframes,noscript,object,ol,optgroup,option,p,param,pre,q,s,samp,script,select,small,span,strike,strong,style,sub,sup,table,tbody,td,textarea,tfoot,th,thead,title,tr,tt,u,ul,var", ",")
    Application.ScreenUpdating = False
    Cells.EntireColumn.Hidden = False
    s = 0
    For p = 1 To 91
        If Cells(2, p) > s Then s = Cells(2, p)
    Next p
    Rows("2:" & s + 3).Delete Shift:=xlUp
    arr = Range(Cells(1, 2), Cells(1, 91))
    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .Navigate "http://de.yusuan.com/index.html"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        For p = 1 To 90
            str1 = arr(1, p)
            Set r = .Document.All.tags(str1)
            Cells(2, p + 1) = r.Length
            For i = 0 To r.Length - 1 '标签的个数
                Cells(i + 3, 1) = i
                Cells(i + 3, p + 1) = r(i).innerText '把第i个标签的内容写入第i+3行,2 * p列
            Next i
        Next p
        .Quit
    End With
    Columns("A:A").Columns.AutoFit
    Rows("1:2").Columns.AutoFit
    For p = 1 To 91
    If Cells(2, p + 1) = 0 Then Columns(p + 1).EntireColumn.Hidden = True
    Next p
    Application.ScreenUpdating = True
    MsgBox "ok"
End Sub

还有查找标签的name的:

Sub 查找标签name()
    Dim arr
    On Error Resume Next
    [a1:cm1] = Split("标签号,a,abbr,acronym,address,applet,area,b,base,basefont,bdo,big,blockquote,body,br,button,caption,center,cite,code,col,colgroup,dd,del,dfn,dir,div,dl,dt,em,fieldset,font,form,frame,frameset,head,h1,h2,h3,h4,h5,h6,hr,html,i,iframe,img,input,ins,kbd,label,legend,li,link,map,menu,meta,noframes,noscript,object,ol,optgroup,option,p,param,pre,q,s,samp,script,select,small,span,strike,strong,style,sub,sup,table,tbody,td,textarea,tfoot,th,thead,title,tr,tt,u,ul,var", ",")
    Application.ScreenUpdating = False
    Cells.EntireColumn.Hidden = False
    s = 0
    For p = 1 To 91
        If Cells(2, p) > s Then s = Cells(2, p)
    Next p
    Rows("2:" & s + 3).Delete Shift:=xlUp
    arr = Range(Cells(1, 2), Cells(1, 91))
    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .Navigate "http://de.yusuan.com/index.html"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        For p = 1 To 90
            str1 = arr(1, p)
            Set r = .Document.All.tags(str1)
            Cells(2, p + 1) = r.Length
            For i = 0 To r.Length - 1 '标签的个数
                Cells(i + 3, 1) = i
                Cells(i + 3, p + 1) = r(i).Name '把第i个标签名写入第i+3行,2 * p列
            Next i
        Next p
        .Quit
    End With
    Columns("A:A").Columns.AutoFit
    Rows("1:2").Columns.AutoFit
    For p = 1 To 91
    If Cells(2, p + 1) = 0 Then Columns(p + 1).EntireColumn.Hidden = True
    Next p
    Application.ScreenUpdating = True
    MsgBox "ok"
End Sub

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-5-31 13:32 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-5-31 18:37 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 蓝天630902 于 2012-6-27 06:56 编辑

也有不灵光的地方,比如说下面的网址:
http://www.tjcae.com/rtjsj/index.htm
但是,网页页面的源码里面,有一个iframe行内框架,这个框架的src(地址)为:“/ShareSubjectList/tradePublicInfo.jsp”也就是“http://www.tjcae.com/ShareSubjectList/tradePublicInfo.jsp”
用这个网址,按照上面的方法得出,“input”的“name”属性为“tradeDateInput”

Sub 天津文化艺术品交易所交易公开信息()
    On Error Resume Next
    With CreateObject("internetexplorer.application")
        .Visible = True
        .Navigate "http://www.tjcae.com/ShareSubjectList/tradePublicInfo.jsp"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        .Document.All.tags("INPUT")(0).Value = "2012-05-28"
        .Document.All.tags("INPUT")(1).Click
    End With
End Sub

----------------------------------
不过本问题无需点击标签,更直接的方法就是:
Sub 天津文化艺术品交易所交易公开信息()
    On Error Resume Next
    With CreateObject("internetexplorer.application")
        .Visible = True
        .Navigate "http://www.tjcae.com/ShareSubjectList/tradePublicInfo.jsp?tradeDateInput=2012-05-28"
        Do Until .ReadyState = 4
            DoEvents
        Loop
    End With
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-5-31 19:46 | 显示全部楼层
本帖最后由 蓝天630902 于 2012-6-4 17:56 编辑

再比如说,http://club.excelhome.net/forum-2-1.html
如何点击“选择主题分类”选择框中的“求助、分享、讨论、原创、推荐、转帖、2007、已解决”

Sub ExcelVBA程序开发ExcelHome论坛灌水机()
    On Error Resume Next
    With CreateObject("internetexplorer.application")
        .Visible = True
        .Navigate "http://club.excelhome.net/forum-2-1.html"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        .Document.All.tags("li")(1).Click '  求助
        '.Document.All.tags("li")(2).Click '  分享
        '.Document.All.tags("li")(3).Click '  讨论
        '.Document.All.tags("li")(4).Click '  原创
        '.Document.All.tags("li")(5).Click '  推荐
        '.Document.All.tags("li")(6).Click '  转帖
        '.Document.All.tags("li")(7).Click '  2007
        '.Document.All.tags("li")(8).Click '  已解决
    End With
End Sub

申明:不可以用本代码去灌水,谁违反本申明,后果自负。

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-6-1 10:32 | 显示全部楼层
本帖最后由 蓝天630902 于 2012-8-28 22:28 编辑

Sub 跳到网易论坛末页()
    On Error Resume Next
    With CreateObject("internetexplorer.application")
        .Visible = True
        .Navigate "http://bbs.news.163.com/bbs/mil/1193698.html"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        While .ReadyState <> 4 Or .Busy
            DoEvents
        Wend
        .Document.All.tags("img")(20).Click
        Set r = .Document.All.tags("a")
        For i = 0 To r.Length
            If Left(r(i).innerText, 2) = "末页" Then
                r(i).Click
                Exit For
            End If
        Next i
    End With
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-6-4 11:42 | 显示全部楼层
本帖最后由 蓝天630902 于 2012-6-4 17:35 编辑

'网页翻页:

'1、可以在网址里面更改页码来翻页,比如:
'“http://club.excelhome.net/thread-849179-5-1.html”
'可以改变上面的红色的“5”来翻页,这个比较简单。

Sub 验证码识别直接判断()
    On Error Resume Next
    With CreateObject("internetexplorer.application")
        .Visible = True
        For p = 1 To 6 '更改页码来翻页
        .Navigate "http://club.excelhome.net/thread-849179-" & p & "-1.html"
        While .ReadyState <> 4 Or .Busy
            DoEvents
        Wend
        Next p
    End With
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-6-4 11:52 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 蓝天630902 于 2012-6-4 17:36 编辑

'网页翻页:

'也可以按照前面的方法,通过点击标签来翻页:
'2、点击标签来翻页,比如:

Sub 价格查询1()
    On Error Resume Next
    With CreateObject("internetexplorer.application")
        .Visible = True
        .Navigate "http://www.dq123.com/price/priceindex.aspx"
            While .ReadyState <> 4 Or .Busy
                DoEvents
            Wend
            Set r = .Document.All.tags("table")(7).Rows
            n = Range("a65536").End(xlUp).Row
            For i = 0 To r.Length - 1
                For j = 0 To r(i).Cells.Length - 1
                If j > 0 And j < 3 Then
                    Cells(i + n + 1, j + 1) = r(i).Cells(j).Title
                Else
                    Cells(i + n + 1, j + 1) = r(i).Cells(j).innerText
                End If
                Next j
            Next i
        For p = 1 To 36639
        Set r1 = .Document.All.tags("a")
        s = r1.Length - 18
       .Document.All.tags("a")(s).Click '点击“下一页”标签翻页
            While .ReadyState <> 4 Or .Busy
                DoEvents
            Wend
            Set r = .Document.All.tags("table")(7).Rows
            n = Range("a65536").End(xlUp).Row
            For i = 0 To r.Length - 1
                For j = 0 To r(i).Cells.Length - 1
                If j > 0 And j < 3 Then
                    Cells(i + n + 1, j + 1) = r(i).Cells(j).Title
                Else
                    Cells(i + n + 1, j + 1) = r(i).Cells(j).innerText
                End If
                Next j
            Next i
       Next p
    End With
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-6-4 11:58 | 显示全部楼层
本帖最后由 蓝天630902 于 2012-6-4 17:37 编辑

网页翻页:

3、可以调用js函数翻页,比如:

Sub 价格查询2()
    On Error Resume Next
    With CreateObject("internetexplorer.application")
        .Visible = True
        .Navigate "http://www.dq123.com/price/priceindex.aspx"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        For p = 0 To 36640
        .Navigate "javascript:gopage(" & p & ")"  '调用js函数翻页
        Do Until .ReadyState = 4
            DoEvents
        Loop
            Set r = .Document.All.tags("table")(7).Rows
            n = Range("a65536").End(xlUp).Row
            For i = 0 To r.Length - 1
                For j = 0 To r(i).Cells.Length - 1
                If j > 0 And j < 3 Then
                    Cells(i + n + 1, j + 1) = r(i).Cells(j).Title
                Else
                    Cells(i + n + 1, j + 1) = r(i).Cells(j).innerText
                End If
                Next j
            Next i
        Next p
    End With
End Sub
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-19 19:11 , Processed in 0.041363 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表