Code Monkey home page Code Monkey logo

chromium_for_spider's Introduction

核心功能

通过修改chromium源码,主要实现两件动态爬虫中比较关注的两个功能:

  1. 禁止当前页面被跳转,同时将即将跳转的URL收集起来备用。这里通过修改了一个比较底层的函数来实现的,不需要做各种场景的hook了。
  2. hook当前页面绑定的所有非默认事件,并保留场景供后续触发。这样爬虫不需要遍历所有DOM节点了。

此外还有一些小功能:

  1. 禁止浏览器下载文件。
  2. 忽视掉"X-Frame-Options"头,即允许任意页面被iframe。
  3. 禁止掉alert,print,confirm,prompt弹窗。
  4. 禁止页面自己打开新窗口;将预备打开的新窗口的URL记录下来。

使用说明

通过修改chromium源码实现了核心功能后,在浏览器的window对象中增加了三个属性:window.infowindow.eventNameswindow.eventNodes

其中window.info将页面中触发的跳转URL等记录了下来,使用_-_分割。

window.eventNameswindow.eventNodes配合使用,eventNames为事件名称,例如clickonmouseover等;eventNodes为事件绑定的DOM节点,通过JS可以获取。使用例子见ch_test/fireevent.html

编译

当前(20190517)使用的chromium版本为dbc6c805b7430f401875d50b8566d9f743ca402b,测试可以很容易就编译成功。可能随着时间推移,chromium的一些依赖会失效,如果失效了,请开issue提醒更新chromium版本。

时至今日chromium的编译已经非常简单了,根据官方步骤,选对开发版本(例如当前使用的dbc6c805b7430f401875d50b8566d9f743ca402b),完全可以做到全程无warning。

官方文档见:https://www.chromium.org/developers/how-tos/get-the-code

注意fetch chromiumgclient sync后,执行git checkout dbc6c805b7430f401875d50b8566d9f743ca402b切换版本,master版本未必都能编译成功。

编译完成后,执行git apply path/to/dbc6c805b7430f401875d50b8566d9f743ca402b.diff应用这个补丁,然后重新编译。

Mac上可执行文件在src/out/Release/Chromium.app/Contents/MacOS/Chromium,Ubuntu上可执行文件在src/out/Release/chrome

chromium_for_spider's People

Contributors

myvyang avatar

Watchers

 avatar  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.