我有一个Excel文件,其中包含我需要打开的所有网址
E.g:
1. example.com/archiveData.php?edit=testcase&id=29
2. example.com/archiveData.php?edit=testcase&id=30
3. example.com/archiveData.php?edit=testcase&id=31
4. example.com/archiveData.php?edit=testcase&id=32
5. example.com/archiveData.php?edit=testcase&id=33
6. example.com/archiveData.php?edit=testcase&id=34
...
(它约有3000个网址T_T)
我无法手动打开它,所以我想用Selenium IDE来做这件事 由于我在Selenium非常新,所以任何人都可以帮我回答我的问题......我可以使用Selenium IDE从Excel数据文件中打开网站URL吗?
或者请提出我可以轻松完成的任何免费工具
非常感谢!
答案 0 :(得分:0)
没有。您不能使用Selenium IDE
来解决您的问题,因为它旨在模拟Web浏览器中的用户操作。但您可以使用编程语言,例如Python
来读取Excel
文件内容(xlrd
模块)并导航到所需的URLs
(Selenium WebDriver
模块)在同一个脚本中。
此外,如果您使用的是Windows
操作系统,则可以尝试使用AutoIT
/ AutoHotKey
自动化工具。
答案 1 :(得分:0)
您可以通过selenium RC或webdriver完成,只需几行代码即可。尝试了解硒的基础知识。
答案 2 :(得分:0)
如果您可以将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,而且代码很短。
如果您有任何疑问,请随时告诉我。我不介意帮你解决这个问题,直到它适合你!