使用Web上的数据,如何login?
我有一个使用“从Web数据”function的macros。 我已经login到网站(在Internet Explorer中),我从中提取数据 – 但是我在Excel中得到的结果只是告诉我,我没有login。
有没有一种特殊的方式来通过Excellogin“数据从networking”? 我知道它是有效的,因为我使用macroslogging器来学习Excel如何获取数据 – 手动这样做,网站要求我在“Excel IE浏览器窗口”中login…但已经过了一个多小时,所以我被注销。 我如何再次login使用它?
这里有适用的数据拉代码(如果有帮助的话)(URLlogin后工作正常):
With ActiveSheet.QueryTables.Add(Connection:="URL;" & theURL, Destination:=webInfoWS.Range("$A$2")) .name = cel.Value & " hex" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "3" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With
同时,我发现了一个工作(主要来自这个线程 ):
在Debug.Print "Opening " & theURL
之后添加Debug.Print "Opening " & theURL
,之前Debug.Print "Opening " & theURL
With ActiveSheet.QueryTables.Add(...)
''' Log in to the web stuff Set ie = CreateObject("InternetExplorer.Application") With ie .Visible = True .Navigate theURL Do Until .READYSTATE = 4 DoEvents Loop If Left(.Document.Title, 5) <> "Welcome!" Then .Document.all.Item("username").Value = "My User Name" .Document.all.Item("password").Value = "MyPassword" .Document.forms(0).submit End If ' .Quit End With ''''''
这样做实际上是打开IE窗口,然后(自动)放入我的用户名和密码,并提交。
但是,如果我再次运行macros(意味着我已经login),这给我一个错误,因为没有用户名/密码inputforms。
思考如何避免 – 使用On Error Goto Next
,但我不喜欢使用,但它可能是最好的select。 我想我会尝试,而不是获得窗口标题(通过HTML),并检查是否是login表单或不…
编辑:关于如何知道.Item("____")
是"username"
和"password"
。 这只是来自HTMLinputID标签:
你会发现在我发现这个post后, .Item()
的文本是不同的 – 我假设,因为该HTML ID是不同的。