for i in range(1, 20): book_name = tree.xpath("/html/body/div[2]/div[2]/div[2]/div[3]/div[' + i + ']/@bookname")[i] book_writer = tree.xpath("/html/body/div[2]/div[2]/div[2]/div[3]/div[' + i + ']/div[2]/div[2]/@title")[i] book_type = tree.xpath("/html/body/div[2]/div[2]/div[2]/div[3]/div[' + i + ']/div[2]/div[2]/a[2]/text()")[i] book_plan = tree.xpath("/html/body/div[2]/div[2]/div[2]/div[3]/div[' + i + ']/div[2]/div[2]/a[3]/text()")[i] book_time = tree.xpath("/html/body/div[2]/div[2]/div[2]/div[3]/div[' + i + ']/div[2]/div[4]/span/text()")[i] book_ticket = tree.xpath("/html/body/div[2]/div[2]/div[2]/div[3]/div[' + i + ']/div[3]/div/div[2]/text()")[i]
参考文献:https://blog.csdn.net/ddzmklhx106577/article/details/102414491?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-8.baidujs&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-8.baidujs