如果您可以將Excel文件轉換爲行分隔的文本文件,那麼通過將文件讀取到數組中,然後在while循環中基於數組操作數據可以很容易地實現這一點。
例子:
Links.txt
www.google.com
www.facebook.com
www.youtube.com
www.tumblr.com
www.amarokstudios.com
OpenLinks.au3
#include <file.au3>
; Create an empty array to store the links later on in the script.
DIM $aArray
; Read you Links.txt file to an array, if there is an error, display an error message.
If _FileReadToArray(@ScriptDir & "\Links.txt", $aArray) then
Else
MsgBox(0,"Error","An error occurred trying to read your file to an array!")
EndIf
; Now, all of the links should be stored in the array called "$aArray". The size of the array is stored in $aArray[0], the first link is in $aArray[1], second in $aArray[2], and so on.
; Now, we are going to declare the starting size of the array, so the loop knows how many times to run the code.
$i = $aArray[0]
; Next, we will declare the link to start on. Since the first link is stored in $aArray[1], we will set the value to 1.
$link = 1
; Now we will create a while loop that will run while the array size is larger than zero.
While $i > 0
; Open the Windows RUN box
Send("#r")
Sleep(250)
; Send the value of $aArray[$link]. Since we previously set $link equal to 1, it will send the value of $aArray[1], which as we said earlier, would contain the first link on our list.
Send($aArray[$link])
; Send the enter key
Send("{ENTER}")
; Sleep for 1 second to prevent code from overlapping itself
Sleep(1000)
#CS
You can put code here to manipulate the data on each website. There are many different ways to do this. For example, if the location for each piece of data is the same, you could simple write one script here that will execute each time a new page loads.
Another method is to create an if statement to check which website is currently loaded, then writing the logic For each page. Tedious, but well worth it if you are going to be doing this for the same pages.
#CE
; Add the value of 1 to the current link variable so the script can move on to the next link. For example, the first value of $aArray[$link] was equal to $aArray[1], but adding 1 to it would change $aArray[$link] to $aArray[2]
$link += 1
; Subtract 1 from the total array size so the loop knows how many more times to execute.
$i -= 1
; End the loop
WEnd
這裏是沒有註釋的代碼,這樣你可以看到它是如何工作的。
#include <file.au3>
Dim $aArray
If _FileReadToArray(@ScriptDir & "\Links.txt",$aArray) then
Else
MsgBox(0,"Error","Error from Function")
EndIf
$i = $aArray[0]
$link = 1
while $i > 0
Send("#r")
Sleep(250)
Send($aArray[$link])
Send("{Enter}")
Sleep(1000)
; Your code to manipulate data here
$link += 1
$i -= 1
WEnd
我知道這並不是專門回答你的問題,但我希望它能爲你提供一個合理的選擇。使用這種方法,您不必下載任何UDF,而且它只是一小段代碼。
如果您有任何問題,請隨時通知我。我不介意幫助你解決這個問題,直到它適合你!
打開網頁後還需要做什麼? 如果你需要截圖AutoIt會做得很好,如果你需要與它交互,那麼你應該學習硒。 – Castilho
是的,這是可以打開從Csv的網址(不是Excel)。打開後你想做什麼?網址將在同一個標籤中打開。 –
謝謝大家,我想打開url然後在鏈接中插入一些數據,我也有一組需要輸入的數據 – Jenny