循环遍历数据帧行

问题描述:

我在数据框中包含链接行.

I have rows of links contained in a dataframe.

df = pd.DataFrame()

我需要一次遍历数据帧中的链接行,以便可以分别在每个链接上执行硒任务.它应该循环遍历这些行,直到数据帧中没有更多行为止.

I need to iterate over the rows of links in the dataframe one at a time so I can perform selenium tasks on each link separately. It should iterate over these rows in a loop until there are no more rows in the dataframe.

     links
0    http://linkone
0    http://linktwo
0    http://linkthree

我的逻辑如下

Loop
    Get http://linkone in first row of dataframe
    Use selenium to perform tasks, such as driver.get(http://linkone)
    Gather data from HTML from http://linkone

    Continue loop and get row 2, row 3, etc.

在这种情况下,您不需要iterrows(),只需使用for循环即可.

In this case you dont need iterrows(), just use a for loop.

只需使用for循环:

for link in df.links:
    print(link)
    print('do something with selenium')

http://linkone
do something with selenium
http://linktwo
do something with selenium
http://linkthree
do something with selenium