近日玩了一个游戏,这里是他的开奖记录,我想用WebBrowser读取所有的记录,原想是找到所有的链接地址后模拟点击鼠标就可以了,可是这个网页的链接地址是JavaScript函数生成的,我想的方法就行不通了。http://www.pceggs.com/play/Pg28history.aspx总之:如果想读取上述网页中5000个开奖记录,用webbrowser怎么自动读取?谢谢高手,我用VB做的。

解决方案 »

  1.   

    webbrowser.Navigate "javascript:......"
      

  2.   

    不管它,链接一样用,比如遍历所有页的记录并保存到文件中,代码如下:
    Option ExplicitDim m_nPage As LongPrivate Sub Form_Load()
        m_nPage = 1
        Open "c:\开奖记录.txt" For Binary As #1
        Me.WebBrowser1.Navigate2 "http://www.pceggs.com/play/Pg28history.aspx"
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        Close #1
    End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        Dim link As Object, table As HTMLTable
        Dim i As Long, j As Long, nStart As Long
        Dim byteLine() As Byte, strLine As String, strCell As String
        
        If URL <> "http://www.pceggs.com/play/Pg28history.aspx" Or m_nPage > 6981 Then Exit Sub
        '提取当前页数据
        Set table = Me.WebBrowser1.Document.All(125)
        nStart = IIf(m_nPage = 1, 0, 1)
        For i = nStart To table.rows.length - 2
            strLine = ""
            For j = 0 To table.rows(i).cells.length - 1
                If j = 2 And i > 0 Then '转换图片为数字
                    strCell = table.rows(i).cells(j).innerHTML
                    strCell = Mid(strCell, 63)
                    strCell = Left(strCell, InStr(strCell, ")") - 1)
                    strCell = Replace(Replace(strCell, "'", ""), ",", "")
                Else
                    strCell = table.rows(i).cells(j).innerText
                End If
                strLine = strLine & vbTab & strCell
            Next
            strLine = Mid(strLine, 2) & vbCrLf
            byteLine = StrConv(strLine, vbFromUnicode)
            Put #1, , byteLine
            Debug.Print strLine
        Next
        '跳转到下一页
        m_nPage = m_nPage + 1
        For Each link In Me.WebBrowser1.Document.links
            If link.href = "javascript:onsubmit(" & m_nPage & ");" Then
                link.Click
                Exit For
            End If
        Next
    End Sub
      

  3.   

    最近想用VB编写一个小程序,自动GOOGLE以下网点:
    http://www.google.com/finance/stockscreener#c0=MarketCap&c1=PE&c2=DividendYield&c3=Price52WeekPercChange&region=us&sector=AllSectors&sort=&sortOrder=右下方的箭头按钮(以查看另20个结果),可是搞定,敬请高手指教!HTML Code:
    <DIV class=tpbd closure_hashCode_f042o7="42">
    <DIV class=SP_arrow_next></DIV></DIV>
    <DIV class=tpsd>21 - 40 of 2658 rows</DIV>
    <DIV class=tpbd closure_hashCode_f042o7="41">
    <DIV class=SP_arrow_previous></DIV></DIV>
    <DIV class=tpbd closure_hashCode_f042o7="40">
    <DIV class=SP_arrow_first></DIV></DIV><SELECT class=tpdd 
    closure_hashCode_f042o7="39"><OPTION value=10>10</OPTION><OPTION selected 
    value=20>20</OPTION><OPTION value=30>30</OPTION></SELECT>
    <DIV class=tpsrd>Show rows:</DIV>