Giter VIP home page Giter VIP logo

crawler's Introduction

Crawler

pyhon爬虫

Scrapy框架使用流程:

scrapy startproject xxx
scrapy genspider xxx "http://www.xxx.com"
编写items.py,明确需要爬取的数据
编写spiders/xxx.py,编写爬虫文件,处理请求和相应,以及提取数据(yield item)
编写pipelines.py,编写管道文件,处理spider返回的item数据,比如本地持久化存储等
编写setting.py,启动管道文件,以及其他相关设置
启动爬虫

报错解决:

1.TypeError: Object of type 'bytes' is not JSON serializable
解决办法:可以自己写一个编码类 `
import json

class MyEncoder(json.JSONEncoder):

def default(self, obj):  
    """  
    只要检查到了是bytes类型的数据就把它转为str类型  
    :param obj:  
    :return: 
    """  
    if isinstance(obj, bytes):  
        return str(obj, encoding='utf-8')  
    return json.JSONEncoder.default(self, obj)    

`
2.代码运行环境用的pycahrm,但是在成功爬虫后,tecent.json用pycahrm打开却是乱码
解决办法:
(1)改变pycharm对于该文件的编码,改为“GBK”
(2)换一个编辑器打开,如notepad

crawler's People

Contributors

yaoyao0808 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.