Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Python 使用Robot框架和Seleniumlibrary,提取数据并保存到txt文件_Python_Selenium_Robotframework - Fatal编程技术网

Python 使用Robot框架和Seleniumlibrary,提取数据并保存到txt文件

Python 使用Robot框架和Seleniumlibrary,提取数据并保存到txt文件,python,selenium,robotframework,Python,Selenium,Robotframework,我目前正在使用Robot框架和Seleniumlibrary开发测试自动化。我的问题是将网站上的链接保存在txt文件中。这可能吗?如果可能,是如何做到的 all_links = driver.find_elements_by_tag_name('a') for a in all_links: print(a.text) #text of the link print(a.get_attribute("href")) #href of the link 不要打印,而是

我目前正在使用Robot框架和Seleniumlibrary开发测试自动化。我的问题是将网站上的链接保存在txt文件中。这可能吗?如果可能,是如何做到的

all_links = driver.find_elements_by_tag_name('a')
for a in all_links:
  print(a.text) #text of the link
  print(a.get_attribute("href")) #href of the link

不要打印,而是根据您认为合适的方式将其写入文本文件。

我解决了这个问题。谢谢您抽出时间。

您到底想抢什么?网址?文本(例如“单击此处”)?无论如何,在决定要在文件中写入什么之后,可以使用库“操作系统”将变量的内容写入文件:我试图获取列表项的文本并将其保存到文件中。谢谢你的帮助。看起来你还没有做过任何研究,而且还不清楚问题的哪一部分需要帮助。首先,我建议您阅读SeleniumLibrary文档和OperatingSystem文档中的内容。谢谢您我通过前面的评论解决了问题。谢谢您的帮助,但我正在处理
.robot
文件。