我创建了一个Python 2.7脚本,它执行以下操作:
- Gets a list of filenames from a folder, and writes them to a csv file, one for each row.
以及
- Enters data into a search box on the web.
- 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)
打开进行读取和附加,存储输出,然后在末尾写入:
相关问题 更多 >
编程相关推荐