print ('Page Loaded')
myelem = driver.find_elements_by_xpath(".//tr[contains(@class, 'inlineListRow')]")
with open("systext.csv","wb") as f:
writer = csv.writer(f)
for myinfo in myelem:
anotherlist = []
itemize = myinfo.find_elements_by_xpath(".//td[contains(@class, 'inlineListBodyCell')]")
for peritem in itemize:
anotherlist.append(peritem.text)
writer.writerows([anotherlist])
for peritem in itemize:
anotherlist.append(peritem.text)
writer.writerows([anotherlist])
我试图从网站中提取信息,然后将其写入csv 我得到所有元素然后得到每个元素的子元素
我得到的代码
问题是完成我的循环需要10分钟才能正常或 我的代码对于任务来说效率不高
数据是13 col乘1800行总大小是400kb
答案 0 :(得分:0)
我不知道整个代码,但它应该是这样的:
print('Page Loaded')
myelem = driver.find_elements_by_xpath(".//tr[contains(@class, 'inlineListRow')]")
async def iterate(w, info):
anotherlist = []
itemize = info.find_elements_by_xpath(".//td[contains(@class, 'inlineListBodyCell')]")
for peritem in itemize:
anotherlist.append(peritem.text)
# if in this nested loop by anotherlist you meant anotherlist2 otherwhise remove it
# anotherlist2.append(peritem.text)
# writer.writerows([anotherlist2])
w.writerows([anotherlist])
return
with open("systext.csv","wb") as f:
writer = csv.writer(f)
for myinfo in myelem:
iterate(writer, myinfo)