#-*—coding:utf8-*-from lxml import etreeimport requestsimport re#编码转换import sysreload(sys)sys.setdefaultencoding("utf-8") headers= { ‘User-Agent‘ : ‘User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36‘ }html = requests.get(‘http://flights.ctrip.com/actualtime/BJS-SHA/t20161223‘, headers = headers ).contentselector = etree.HTML(html) urllist = selector.xpath(‘//div[@class="search-bd"]/ul/li[@class="fly-row"]/div[@class="inl flight"]/strong/text()‘) for i in urllist: print i
时间: 2025-01-02 01:32:48