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. nginx-启动|关闭|重新加载配置文件的命令

    1.1 进入操作目录 D: cd D:\NginxTest\nginx-1.10.2 1.2 启动指令 nginx -c conf\nginx.conf 1.3 关闭指令 nginx -s stop ...

  2. ethereum发erc20token

    以太坊发币智能合约代码简单介绍: 发币代码如下(https://ethereum.org/token#the-code网站中获得): pragma solidity ^; interface toke ...

  3. iOS - 切换rootViewController时,销毁之前的控制器

    一.iOS在切换根控制器时,如何销毁之前的控制器?(切换rootViewController时注意的内存泄漏) 首先.在iOS的ARC机制下,任何对象,当没有其他对象对他进行强引用时,都会被自动释放. ...

  4. 实现调用Android手机的拍照功能

    很简单,直接上示例吧 1 xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...

  5. Spark LogisticRegression 逻辑回归之简介

    LogisticRegression简介

  6. 数据结构与算法——基数排序简单Java实现

    基数排序(radix sort)又称“桶子法”,在对多个正整数进行排序时可以使用.它的灵感来自于队列(Queue),它最独特的地方在于利用了数字的有穷性(阿拉伯数字只有0到9的10个). 基数排序使用 ...

  7. 三剑客之grep

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...

  8. 栈的C语言实现

    在C++中,可以直接使用std::stack C语言实现如下: stack.c /** * @file stack.c * @brief 栈,顺序存储. * * * */ #include <s ...

  9. 洛谷 P1208混合牛奶【贪心】

    题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是 ...

  10. POJ 1854 - Evil Straw Warts Live

    Description A palindrome is a string of symbols that is equal to itself when reversed. Given an inpu ...