使用calibre获取静觅爬虫学习系列教程

好像页面的处理做的不是很好

#coding='gbk'
from calibre.web.feeds.recipes import BasicNewsRecipe
import re
class lhxy(BasicNewsRecipe):
    title = u"静觅爬虫学习系列教程"  
    description = u"..."
    language = 'zh'
    max_articles_per_feed = 1000
    oldest_article = 500
    remove_javascript = True
    cover_url = 'https://xxx.jpg' #自己换成个封面链接
    no_stylesheets = True 
    keep_only_tags =[dict(name='h1', attrs={'class':'article-title'}),
    dict(name='article', attrs={'class':'article-content'}),]
    def get_title(self,link):
        return link.contents[0].strip()
    def parse_index(self):
        contents_soup = self.index_to_soup('http://cuiqingcai.com/1052.html')
        trans_Elem = contents_soup.find('article', attrs={'class': "article-content"})
        contents_Elem=trans_Elem.findAll('p')
        mn=[]
        for link in contents_Elem:
            xx=link.a
            if xx==None:
                continue
            mn.append(xx)
        articles = []
        for link1 in mn:
            title=self.get_title(link1)
            title = title.encode("utf-8")
            url = link1['href']
            gather = {'title':title,'url':url}
            articles.append(gather)
        ans = [(u'静觅爬虫学习系列教程',articles)]
        return ans
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,372评论 25 708
  • 1 在自我修行里面,放下是我们说的最多的一个词语。 放下一段感情,放下一件事情,放下一段牵挂,放下一份工作。 期间...
    诺亚nuoya阅读 950评论 0 3