import requests
import re
import json
from requests.exceptions import RequestException

def get(url):
    try:
        headers = {
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
        }
        response = requests.get(url,headers = headers)
        if response.status_code == 200:
            return response.text
        return None
    except RequestException:
        return None
def parse(html):
    patter = re.compile('<li.*?cover.*?href="(.*?)"\stitle="(.*?)">.*?more-meta.*?author">(.*?)</span>.*?year">(.*?)</span>.*?publisher">(.*?)</span>.*?</li>',re.S)
    items = re.findall(patter,html)
    for i in items:
        yield {
            'url': i[0],
            'title': i[1],
            'name': i[2].strip(),
            'date': i[3].strip(),
            'pulisher': i[4].strip()
        }
def  write_to_file (content):
    with open('result.txt','a',encoding='utf-8') as f:
        f.write(json.dumps(content,ensure_ascii=0)+'\n')
        f.close()
def main():
    url = 'https://book.douban.com/'
    html = get(url)
    for i in parse(html):
        print(i)
        write_to_file(i)

if __name__ == '__main__':
    main()

照葫芦画瓢之爬虫豆瓣top100的更多相关文章

  1. 放养的小爬虫--豆瓣电影入门级爬虫(mongodb使用教程~)

    放养的小爬虫--豆瓣电影入门级爬虫(mongodb使用教程~) 笔者声明:只用于学习交流,不用于其他途径.源代码已上传github.githu地址:https://github.com/Erma-Wa ...

  2. 第三百三十五节,web爬虫讲解2—Scrapy框架爬虫—豆瓣登录与利用打码接口实现自动识别验证码

    第三百三十五节,web爬虫讲解2—Scrapy框架爬虫—豆瓣登录与利用打码接口实现自动识别验证码 打码接口文件 # -*- coding: cp936 -*- import sys import os ...

  3. Forward团队-爬虫豆瓣top250项目-项目总结

    托管平台地址:https://github.com/xyhcq/top250 小组名称:Forward团队 组长:马壮 成员:李志宇.刘子轩.年光宇.邢云淇.张良 我们这次团队项目内容是爬取豆瓣电影T ...

  4. Forward团队-爬虫豆瓣top250项目-设计文档

    组长地址:http://www.cnblogs.com/mazhuangmz/p/7603594.html 成员:马壮,李志宇,刘子轩,年光宇,邢云淇,张良 设计方案: 1.能分析HTML语言: 2. ...

  5. Forward团队-爬虫豆瓣top250项目-需求分析

    一. 需求:1.爬取豆瓣电影top250. 2.获取电影名称,排名,分数,简介,导演,演员. 3.将爬取到的数据保存,以便随时查看. 3.可以将获取到的数据展示给用户. 二. 参考: 豆瓣api参考资 ...

  6. 《Forward团队-爬虫豆瓣top250项目-设计文档》

    成员:马壮,李志宇,刘子轩,年光宇,邢云淇,张良 设计方案: 1.能分析HTML语言: 2.提取重要数据,并保存为文本文档: 3.用PY代码调取文本文档的数据: 4.编写提取部分数据的python代码 ...

  7. Forward团队-爬虫豆瓣top250项目-开发文档

    项目地址:https://github.com/xyhcq/top250 我在本次项目中负责写爬虫中对数据分析的一部分,根据马壮分析过的html,我来进一步写代码获取数据,具体的功能及实现方法我已经写 ...

  8. Forward团队-爬虫豆瓣top250项目-模块测试

    项目托管平台地址:https://github.com/xyhcq/top250 模块测试:爬虫对信息的处理部分 测试方法: 实际运行一下代码: 可以看见,信息都已经爬取出来了 其他补充说明: 原本系 ...

  9. Forward团队-爬虫豆瓣top250项目-模块开发过程

    项目托管平台地址:https://github.com/xyhcq/top250 开发模块功能: 爬虫对信息的处理部分 开发时间:5天的下午空余时间(每天大约1小时,边学模块的使用边开发) 实现了:爬 ...

随机推荐

  1. MySQL 无法连接

    Host 'localhost' is not allowed to connect to this MySQL server 错误 解决办法: C:\Program Files\MySQL\MySQ ...

  2. nginx 动静分离(相同URL)

    #报表 location ~* /(report)/ { if ($request_uri !~* .*(jd|taobao|operator).* ){ proxy_pass http://tweb ...

  3. day_6.6 py

    Tftp 下载器演示 2018-6-6 14:11:09 #!/usr/bin/env python #!--*--coding:utf-8 --*-- #!@Time :2018/6/6 11:55 ...

  4. 【react】---手动封装一个简易版的redux---【巷子】

    export let createStore = (reducer)=>{ //定义默认的state let state = {}; //定义默认的action let actionTypes ...

  5. 《手机端》让多出的导航变水平拖动,不让他 float 撑下去

    /********** 网站底部 **************/ .nav{;;;;white-space: nowrap;overflow: auto;-webkit-overflow-scroll ...

  6. WordPlayer

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  7. asp.net Ajax调用Aspx后台方法

    Ajax调用的前提(以aspx文件为例:) 1.首先需要在aspx文件后台中引用using System.Web.Services; 2.需要调用的方法必须是公共的(public).静态的(stati ...

  8. GIAC2018全球互联网架构大会深圳站盛况回顾,定格精彩瞬间!

    6月1日至2日,由知名软件培训公司msup和高可用架构联合推出的GIAC全球互联网架构大会在深圳华侨城洲际大酒店盛大召开.来自国内外顶级互联网公司.诸多著名科技图书作者在内的71名海内外著名专家与现场 ...

  9. 更换title上的ico

    var rurl = "/static/dashboard/img/favicon.ico"; var a = ''; var links = document.getElemen ...

  10. ubuntu16.04安装kinetic调用gazebo_control解决方案

    解决方案 sudo apt-get install ros-kinetic-gazebo-ros-control