ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1208|回复: 3

登陆网页获取信息,终于做出来了,分享一下,

[复制链接]

TA的精华主题

TA的得分主题

发表于 2020-8-7 00:14 来自手机 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 lulu8988 于 2020-8-9 13:38 编辑

网页:https://448282.yichafen.com/public/queryscore/sqcode/OsDcQnymODU4fDFhYWVkNzBjODBkMGQzYmRlZWRlNWZiNzVlMDZlOTEzfDQ0ODI4MgO0O0OO0O0O.html
(自建的网页查询,不涉及别人的隐私)

终于做出来自已想要的样子了,感谢各位曾给于指导的老师,谢谢!!
现发出来分享一下,一起学习,

Sub 测试4()
'''''''''''''''''''''要把IE浏览器设置成默认的浏览器
Dim aaa%, n%, str As String
aaa = Sheet1.Columns(1).Find("*", , xlFormulas, , , xlPrevious).Row
For n = 2 To aaa
    Dim IE As InternetExplorer
    Dim doc As HTMLDocument
    Set IE = New InternetExplorer
    IE.navigate "https://448282.yichafen.com/public/queryscore/sqcode/OsDcQnymODU4fDFhYWVkNzBjODBkMGQzYmRlZWRlNWZiNzVlMDZlOTEzfDQ0ODI4MgO0O0OO0O0O.html"
    IE.Visible = False

    Do
      DoEvents
    Loop Until IE.readyState = 4

    Set doc = IE.document
    doc.getElementById("s_xingming").Value = Sheet1.Range("a" & n)
    doc.getElementById("s_kaohao").Value = Sheet1.Range("b" & n)
    doc.getElementById("yiDunSubmitBtn").Click

   Application.Wait (Now + TimeValue("00:00:02"))

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim Obj As Object
    On Error Resume Next
    For Each Obj In CreateObject("Shell.Application").Windows
        If TypeName(Obj.document) = "HTMLDocument" Then

        Sheet1.Range("i" & n) = Obj.LocationURL

        End If
    Next


If Sheet1.Range("i" & n) = "https://448282.yichafen.com/public/queryresult.html" Then

     my_string = IE.document.all.tags("html")(0).outerHTML   ''''''''''''''''
     my_exp = "<td"
     Index = InStr(my_string, my_exp)
     If Index > 0 Then

  Dim jiequ As String
  jiequ = Mid(IE.document.all.tags("html")(0).outerHTML, Index, 200)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''不会用数组,只能这样了,
kaohaoN = InStr(jiequ, ">")
kaohaoM = InStr(jiequ, "/td><td")
Dim kaohao1 As String, kaohao2 As String
kaohao1 = Mid(jiequ, kaohaoN + 10, 165)
kaohao2 = Mid(jiequ, kaohaoN + 1, kaohaoM - 2 - kaohaoN)
Sheet1.Range("c" & n) = kaohao2


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
xingmingN = InStr(kaohao1, "rap")
xingmingM = InStr(kaohao1, "</td><td")
Dim xingming1 As String, xingming2 As String
xingming1 = Mid(kaohao1, xingmingN + 20, 155)
xingming2 = Mid(kaohao1, xingmingN + 13, xingmingM - xingmingN - 13)
Sheet1.Range("d" & n) = xingming2


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
wuwenN = InStr(xingming1, "rap")
wuwenM = InStr(xingming1, "</td><td")
Dim wuwen1 As String, wuwen2 As String
wuwen1 = Mid(xingming1, wuwenN + 20, 135)
wuwen2 = Mid(xingming1, wuwenN + 13, wuwenM - wuwenN - 13)
Sheet1.Range("e" & n) = wuwen2

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
shuN = InStr(wuwen1, "rap")
shuM = InStr(wuwen1, "</td><td")
Dim shu1 As String, shu2 As String
shu1 = Mid(wuwen1, shuN + 20, 120)
shu2 = Mid(wuwen1, shuN + 13, shuM - shuN - 13)
Sheet1.Range("f" & n) = shu2

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
eN = InStr(shu1, "rap")
eM = InStr(shu1, "</td>")
Dim e1 As String, e2 As String
e1 = Mid(shu1, eN + 20, 82)
e2 = Mid(shu1, eN + 13, eM - eN - 13)
Sheet1.Range("g" & n) = e2

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Ln = InStr(e1, "rap")
lM = InStr(e1, "</td><td")
Dim l1 As String, l2 As String
l1 = Mid(e1, Ln + 20, 82)
l2 = Mid(e1, Ln + 13, lM - Ln - 13)
Sheet1.Range("h" & n) = l2


Sheet1.Range("j" & n) = "YES"

     Else
'       MsgBox "出错"
     End If
Else

Sheet1.Range("j" & n) = "NO"
End If

    doc.Close

    Set doc = Nothing

    IE.Quit

    Set IE = Nothing

   Application.Wait (Now + TimeValue("00:00:01"))

Next

    End Sub



TA的精华主题

TA的得分主题

发表于 2020-8-31 09:07 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
ie大法

TA的精华主题

TA的得分主题

发表于 2020-10-5 07:34 来自手机 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2020-10-8 00:40 来自手机 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-11-25 20:56 , Processed in 0.027510 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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