jeff
jeff
这家伙很懒,什么也没写!

注册于 2年前

回答
1
文章
1
关注者
0

books = html.xpath('//tr[@class="item"]')
 quotes = []
    for l in books:
        quote = l.xpath('td[2]/p[@class="quote"]/span/text()')
        print(quote)
        print(len(quote))
        quotes.append(quote[0] if(len(quote) == 1) else " ")

通过取出所有类为item的tr为变量books,循环取出books第二个td标签下类名为 quote的p标签下的span标签的内容,定义列表,追加元素,追加元素时添加判断,若取出列表长度为0,则存入空,否则存入第一个列表元素

发布
问题