Git Product home page Git Product logo

autohome_spider's Introduction

汽车之家爬虫(AutoHome_spider)

Language

把人类从重复的劳动中解放出来,去创造新的事物。

简介(Introduction)

汽车之家可以说是非常大的一个汽车论坛了,本项目是为了研究某款车型的口碑开发的,能够定向的获取某款车型的帖子以及评论。解决了该网站的字体反爬虫。

快速开始(Quick start)

环境要求(Requirements):

  • Python 3.x (2.x is not supported)
  • requests
  • bs4
  • fontTools
  • pyecharts (绘图,只用爬虫无需此库)
  • snownlp (自然语言处理,只用爬虫无需此库)

操作步骤(Steps):

  1. Git本项目到您的电脑上,或是直接Fork到您自己的仓库

     git clone https://github.com/StuPeter/AutoHome_spider.git
    
  2. 目录结构如下:

     .
     ├── TTF
     │   ├── 03.ttf
     │   ├── standardFont.ttf
     │   └── temp.ttf
     ├── AnalysisData.py
     ├── AutoHomeFont.py
     ├── AutoHomeSpiderClass.py
     ├── main.py
     ├── targetCarUrl.txt
     ├── requirements.txt
     └── Readme.md
    
    • TTF文件夹为字体包;03.ttf为测试字体;standardFont.ttf为标准字体用于对比;temp.ttf为临时字体是每次下载会自动替换;
    • AnalysisData.py为我自己的分析程序,对您基本没用;
    • AutoHomeFont.py为字体替换程序,用于解决汽车之家的字体反爬;
    • AutoHomeSpiderClass.py为解析和下载的类,供main.py调用;
    • main.py为主程序,用于爬取帖子;
    • targetCarUrl.txt存储车型论坛链接和ID,可自动更新;
  3. 在开始之前,需要先打开main.py,拉到最底部可以看到如下程序:

     if __name__ == '__main__':
         # 更新targetCarUrl.txt
         updateCarUrl()
         # 爬虫主程序
         #main(pageIndex=1, BBSId=352)
    

    建议您先注释 main() ,运行 updateCarUrl() 。这会帮您更新targetCarUrl.txt,在该文件中,您可以获取您想要车型的BBSId。 其中 updateCarUrl() 可以传入参数,例如 updateCarUrl("奔驰"),将只会获取所有奔驰车型的BBSId。

  4. 同样在main.py中:

    注释 updateCarUrl(),填入 main() 函数的参数:pageIndex和BBSId,其中pageIndex为该车型论谈的页码,BBSId可去targetCarUrl.txt中查找。

  5. 如上设置设置完毕后,直接运行main.py即可。ps:由于是单线程下载,可能需要较长时间,如果是固定IP请注意爬取的时间间隔,默认2秒。

  6. 最后爬取完毕后,会生成你选定的BBSId_post.csv里面的数据格式如下:

      ['用户名', '精华帖数量', '发帖量', '回帖量', '注册日期', '地理位置', '回复日期', '回复内容']
    

许可(License)

MIT license

autohome_spider's People

Contributors

stupeter avatar

Watchers

 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.