循环从csv检索数据,附加到fi

2024-06-02 05:30:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个Python 2.7脚本,它执行以下操作:

  1. Gets a list of filenames from a folder, and writes them to a csv file, one for each row.

以及

  1. Enters data into a search box on the web.
  2. Writes the result from the search box into another csv file.

所以我现在想要的是,让(1)中的csv数据作为(2)的输入。在

也就是说,对于csv文件中的每个文件名,它都会搜索该单元格。在

另外,我不想仅仅将结果写入(3)中的第二个csv文件,而是将结果附加到第一个csv文件中,或者生成一个包含两个列的新csv文件。在

我可以提供代码,但是因为已经有50行了,所以我试图保持这个问题的描述性。在

更新:建议的检索和附加:

with open("file.csv","a+") as f:
    r = csv.reader(f)
    wr = csv.writer(f, delimiter="\n")
    result = []
    for line in r:
        searchbox = driver.find_element_by_name("searchbox")
        searchbox.send_keys(line)

        sleep(8)

        search_reply = driver.find_element_by_class_name("search_reply")

        result = re.findall("((?<=\()[0-9]*)", search_reply.text)
    wr.writerow(result)

Tags: 文件csvthefromboxforsearchdriver