爬取起点中文网

import requests
from lxml import etree
for page in range(1,15):
    url = 'https://www.qidian.com/all?orderId=&style=1&pageSize=20&siteid=1&pubflag=0&hiddenField=0&page=%s'%page
    response = requests.get(url)
    root = etree.HTML(response.content)
    fiction_list = root.xpath("//ul[@class='all-img-list cf']/li")

    for fiction in fiction_list:
        fiction_name = fiction.xpath("div/h4/a/text()")[0]
        fiction_author = fiction.xpath("div[@class='book-mid-info']/p[@class='author']/a[@class='name']/text()")[0]
        fiction_cla = fiction.xpath("div[@class='book-mid-info']/p[@class='author']/a[@class='go-sub-type']/text()")[0]
        fiction_intro = fiction.xpath("div[@class='book-mid-info']/p[@class='intro']/text()")[0].strip()
        file = open('起点中文网.txt', 'a', encoding='gb18030')
        file.write(fiction_name + '\n' + fiction_author + '\n' + fiction_cla + '\n' + fiction_intro)
        file.write('\n')
        file.write('\n')
        file.close()

爬取起点中文网_第1张图片

你可能感兴趣的:(Python)