# -*- coding:utf-8 -*- from lxml import etree import requests ##先进单页测试,然后在进行多页循环 没有解决的问题,动态解决最大页数,目前是默认11页 for page in range(1,12): for i in range(1,21):##每页都是20条信息,每一行5列信息 for j in range(1,6): ##单页测试 url = 'http://www.tbia.cn/cn/dynamicflight/dynamicflightInfo/list.do?page='+str(page) headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'} data = requests.get(url, headers=headers) data.encoding = 'utf-8' ##中文乱码解决方案 s = etree.HTML(data.text) info = s.xpath('//table[@class="flighttable"]/tbody/tr['+str(i)+']/td['+str(j)+']/node()') # **机场 print("第 "+str(page)+"页"+"第 "+str(i)+"行"+"第 "+str(j)+"列") list.append(info) print(list) ##list即为结果