Python+;硒+;拉网慢

Python+;硒+;拉网慢,python,selenium,Python,Selenium,我试图从一个网站中提取信息,然后将其写入csv 我得到所有元素,然后得到每个元素的子元素 我得到的代码有效 问题是,完成我的循环需要10分钟以上,这是正常还是正常 我的代码是否对任务无效 数据是13列乘以1800行,总大小是400kb,我不知道整个代码,但应该是这样的: MyLem中myinfo的“内部作用域:”您可以执行异步操作。还有为什么你要重复和嵌套“peritem in itemize:”-这是低效的。我才刚开始,你能详细说明你的第一句话吗。我要试试你的第二句话。我想我必须用1asyn

我试图从一个网站中提取信息,然后将其写入csv 我得到所有元素,然后得到每个元素的子元素

我得到的代码有效

问题是,完成我的循环需要10分钟以上,这是正常还是正常 我的代码是否对任务无效


数据是13列乘以1800行,总大小是400kb,我不知道整个代码,但应该是这样的:


MyLem中myinfo的“内部作用域:”您可以执行异步操作。还有为什么你要重复和嵌套“peritem in itemize:”-这是低效的。我才刚开始,你能详细说明你的第一句话吗。我要试试你的第二句话。我想我必须用1async def iterate来分离tr元素1的td元素,它返回一个错误,一旦我删除了async,它就工作得很好,所以谢谢你。我会记下答案。然而,如果你能告诉我如何加快我的代码,我将不胜感激。据我所知,您在循环之外创建了一个函数,做了同样的事情。您使用哪一版本的python?在3.6中,它应该可以工作,但对于旧版本,您需要使用asyncore和asynchat模块。
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]) 
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)