Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3192|回复: 6

[已解决]制做一个宏可以直接提取网页内ID名

[复制链接]
发表于 2011-3-7 22:14 | 显示全部楼层 |阅读模式
10学分
2.jpg 从选定的网址里提取网站的淘宝ID(只要ID,提取在表格内即可,其它不要),序号总共有六千行。
最佳答案
2011-3-9 12:53
Option Explicit

Sub 提取淘宝ID()
    Dim i As Long
    Dim oHttp As Object

    Dim nRow As Long
    Dim cTxt As String, arr(), brr()
    Dim arrTmp As Variant

    On Error Resume Next
    nRow = ActiveSheet.Range("e65536").End(xlUp).Row
    arr = Range("E7:E" & nRow).Value
    ReDim brr(7 To nRow, 1 To 1)
    Set oHttp = CreateObject("Microsoft.XMLHTTP")
    With oHttp
        For i = 1 To nRow
            DoEvents
            .Open "GET", arr(i, 1), False
            .Send
            Do While Not .READYSTATE = 4
                DoEvents
            Loop

            arrTmp = Split(.responsetext, "请进入")
            If IsArray(arrTmp) Then
                If UBound(arrTmp) > 0 Then
                    arrTmp = Split(arrTmp(1), "的")
                    If IsArray(arrTmp) Then
                        brr(6 + i, 1) = arrTmp(0)
                    End If
                End If
            End If
        Next
    End With
    Set oHttp = Nothing
    ActiveSheet.Range("F7:F" & nRow).Value = brr
End Sub

提取ID.rar (18.57 KB, 下载次数: 12)

提取ID.rar

10.93 KB, 下载次数: 16

 楼主| 发表于 2011-3-7 22:15 | 显示全部楼层
可以的话直接联系本人,,,QQ:2189901谢谢。。金币还有。
回复

使用道具 举报

 楼主| 发表于 2011-3-8 13:36 | 显示全部楼层
Sub 查询()
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error Resume Next
Dim nRow%, cTxt$, ARR(), Brr()
nRow = ActiveSheet.Range("a65536").End(xlUp).Row
ARR = Range("a1:a" & nRow).Value
ReDim Brr(1 To nRow, 1 To 1)
   
    With CreateObject("Microsoft.XMLHTTP")
        For I = 1 To nRow
            DoEvents
            .Open "POST", "htp;333sh.gov.cn/rdb/SearchOK.jsp?sfzh=" & ARR(I, 1), False
            .setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"
            .Send
            Do While Not .READYSTATE = 4
                DoEvents
            Loop
            cTxt = Split(Split(Split(Split(Split(.responsetext, "<TABLE", , vbBinaryCompare)(2), "<TR>", , vbBinaryCompare)(4), "<TD", , vbBinaryCompare)(6), ">", , vbBinaryCompare)(1), "<", , vbBinaryCompare)(0)
            If Err = 0 Then Brr(I, 1) = cTxt
            Err.Clear
        Next
    End With
ActiveSheet.Range("b1:b" & nRow).Value = Brr
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
利用此样版应该可以弄出来。。有高手吗?
回复

使用道具 举报

 楼主| 发表于 2011-3-9 09:31 | 显示全部楼层
高手速度来。。
回复

使用道具 举报

 楼主| 发表于 2011-3-9 09:32 | 显示全部楼层
Sub 提取淘宝ID()
Application.EnableEvents = False
On Error Resume Next
Dim nRow%, cTxt$, ARR(), Brr()
nRow = ActiveSheet.Range("e65536").End(xlUp).Row
ARR = Range("E7:E" & nRow).Value
ReDim Brr(7 To nRow, 7 To 1)
    With CreateObject("Microsoft.XMLHTTP")
        For I = 1 To nRow
            DoEvents
            .Open "POST", ARR(I, 7), False
            .setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"
            .Send
            Do While Not .READYSTATE = 4
                DoEvents
            Loop
             cTxt = Split(Split(Split(Split(Split(.responsetext, "请进入", , 1)(2), "淘宝网首页", , 1)(4), "更多充值平台加款卡", , 1)(6), "铺", , 1)(1), "的", , 1)(0)
             If Err = 0 Then Brr(I, 7) = cTxt
            Err.Clear
        Next
    End With
ActiveSheet.Range("G7:G" & nRow).Value = Brr
Application.EnableEvents = True
End Sub
回复

使用道具 举报

发表于 2011-3-9 12:53 | 显示全部楼层    本楼为最佳答案   
Option Explicit

Sub 提取淘宝ID()
    Dim i As Long
    Dim oHttp As Object

    Dim nRow As Long
    Dim cTxt As String, arr(), brr()
    Dim arrTmp As Variant

    On Error Resume Next
    nRow = ActiveSheet.Range("e65536").End(xlUp).Row
    arr = Range("E7:E" & nRow).Value
    ReDim brr(7 To nRow, 1 To 1)
    Set oHttp = CreateObject("Microsoft.XMLHTTP")
    With oHttp
        For i = 1 To nRow
            DoEvents
            .Open "GET", arr(i, 1), False
            .Send
            Do While Not .READYSTATE = 4
                DoEvents
            Loop

            arrTmp = Split(.responsetext, "请进入")
            If IsArray(arrTmp) Then
                If UBound(arrTmp) > 0 Then
                    arrTmp = Split(arrTmp(1), "的")
                    If IsArray(arrTmp) Then
                        brr(6 + i, 1) = arrTmp(0)
                    End If
                End If
            End If
        Next
    End With
    Set oHttp = Nothing
    ActiveSheet.Range("F7:F" & nRow).Value = brr
End Sub

提取ID.rar (18.57 KB, 下载次数: 12)
回复

使用道具 举报

发表于 2011-3-9 13:09 | 显示全部楼层
我是来学习的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-23 15:38 , Processed in 0.235224 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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