#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@Date : 2019/08/20 09:44
@Author :wuyupku
@File : shigeSpider.py
'''
from utils import MySpider, MongoBase
from datetime import date
from lxml import etree
import sys
class shigeSpider():
def __init__(self):
self.db = MongoBase()
self.spider = MySpider()
def download(self, url):
self.domain = url.split('/')[2]
data = self.spider.get(url)
if data:
self.parse(data)
def parse(self, data):
response = etree.HTML(data)
for row in response.xpath('//div[@class="left"]/div[@class="sons"]'):
title = row.xpath('div[@class="cont"]/p/a/b/text()')[0] if row.xpath('div[@class="cont"]/p/a/b/text()') else ''
dynasty = row.xpath('div[@class="cont"]/p[@class="source"]//text()')[0] if row.xpath('div[@class="cont"]/p[@class="source"]//text()') else ''
author = row.xpath('div[@class="cont"]/p[@class="source"]//text()')[-1]
Python唐诗生成器
最新推荐文章于 2022-05-24 15:29:47 发布
