#coding=utf-8 import requests from lxml import etree import sys reload(sys) sys.setdefaultencoding('utf-8') for num in range(1,36): url = 'http://www.qiushibaike.com/8hr/page/'+str(num) html = requests.get(url).text selector = etree.HTML(html) content = selector.xpath('//div[@id="content-left"]/div[@class="article block untagged mb15"]/div[@class="content"]/text()') print '正在抓取第'+str(num)+'頁:url:'+url for each in content: f = open('./qiubai1.txt','a') f.write(each+'\n') f.close()