python, lxml and xpath - html table parsing

后端 未结 2 1502
抹茶落季
抹茶落季 2021-02-06 13:19

I \'am new to lxml, quite new to python and could not find a solution to the following:

I need to import a few tables with 3 columns and an undefined number of rows star

2条回答
  •  眼角桃花
    2021-02-06 13:40

    You need to use a loop to access the row's data, like this:

    for row in data:  
        for col in row:
            print col
    

    Calling next() once as you did will access only the first item, which is why you see one column.

    Note that due to the nature of generators, you can only access them once. If you changed the call process_row(row) into list(process_row(row)), the generator would be converted to a list which can be reused.

    Update: If you need just the 3rd row and on, use data[2:]

提交回复
热议问题