Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
简单选择所有文本&;使用Selenium&;保存到文件;VBA_Vba_Selenium - Fatal编程技术网

简单选择所有文本&;使用Selenium&;保存到文件;VBA

简单选择所有文本&;使用Selenium&;保存到文件;VBA,vba,selenium,Vba,Selenium,我是selenium的新手,不熟悉它的语法 我正在尝试找出如何发送控件A并将所有选定文本保存到文件中 如果有人可以发布一些发送控件A的示例&将所有选定的文本保存到基本文本文件中,这将为我节省大量时间 我已经设法让selenium正常工作,但无法理解其语法,因为它与Vba不同 谢谢 Public Sub scrapeCIL() Dim bot As New WebDriver, posts As WebElements, post As WebElement, i As Integer, mysh

我是selenium的新手,不熟悉它的语法

我正在尝试找出如何发送控件A并将所有选定文本保存到文件中

如果有人可以发布一些发送控件A的示例&将所有选定的文本保存到基本文本文件中,这将为我节省大量时间

我已经设法让selenium正常工作,但无法理解其语法,因为它与Vba不同

谢谢

Public Sub scrapeCIL()
Dim bot As New WebDriver, posts As WebElements, post As WebElement, i As Integer, mysheet As Worksheet, keys As Selenium.keys
bot.Start "chrome", "https://www.binance.com/en/trade/BTC_USDT"
bot.Get "/"


bot.Quit
End Sub

您可以使用以下代码执行
CTRL+A

wd.findElementByTagName("body").click
wd.SendKeys Keys.Control, "a"
然后创建文本文件并按如下方式编写:

Option Explicit

' Go to Tools -> References... and check "Microsoft Scripting Runtime" to be able to use
' the FileSystemObject which has many useful features for handling files and folders
Public Sub SaveTextToFile()

    Dim filePath As String
    filePath = "C:\temp\MyTestFile.txt"

    ' The advantage of correctly typing fso as FileSystemObject is to make autocompletion
    ' (Intellisense) work, which helps you avoid typos and lets you discover other useful
    ' methods of the FileSystemObject
    Dim fso As FileSystemObject
    Set fso = New FileSystemObject
    Dim fileStream As TextStream

    ' Here the actual file is created and opened for write access
    Set fileStream = fso.CreateTextFile(filePath)

    ' Write something to the file
    fileStream.WriteLine "something"

    ' Close it, so it is not locked anymore
    fileStream.Close

    ' Here is another great method of the FileSystemObject that checks if a file exists
    If fso.FileExists(filePath) Then
        MsgBox "Yay! The file was created! :D"
    End If

    ' Explicitly setting objects to Nothing should not be necessary in most cases, but if
    ' you're writing macros for Microsoft Access, you may want to uncomment the following
    ' two lines (see https://stackoverflow.com/a/517202/2822719 for details):
    'Set fileStream = Nothing
    'Set fso = Nothing

End Sub

参考摘自

Hi,感谢回复Hi,感谢回复我应该说使用控件a直接从浏览器中以selenium保存所选文本,而不是vba我知道如何使用vba保存文件,但我不知道如何使用selenium直接从浏览器中保存文本谢谢@GenusMax:复制的文本在通用剪贴板中,您可以从剪贴板中读取吗?顺便说一句,CTRL+a对您有效吗?您好,我尝试了bot.findElementByTagName(“body”)。单击bot.SendKeys.Control,“a”,但它给出的对象不支持此方法或属性错误。我只需要每隔1秒保存所有文本并将其保存到文件中。不必使用Ctrl A。文本必须保存到变量,而不是剪贴板。我不能使用剪贴板,因为我在另一个脚本中使用了剪贴板。谢谢