Как лучше написать чекер позиций в google?

Discussion in 'Общие вопросы программирования' started by mail156, 10 Jun 2019.

  1. mail156

    mail156 Banned

    Joined:
    28 Sep 2018
    Messages:
    464
    Likes Received:
    357
    Reputations:
    0
    Как лучше написать чекер позиций сайтов в google: на php+curl или php+c++демон на qt?
     
  2. ckpunmkug

    ckpunmkug Member

    Joined:
    20 Mar 2017
    Messages:
    73
    Likes Received:
    72
    Reputations:
    10
    Я бы сделал в браузере расширением. Будет удобней каптчу преодолевать.
    Вот код который парсит выдачу
    Code:
    // Script for inject to google page.
    // This script finds links (anchros html elements) and returns them to the background script.
    // Out:
    //     {
    //        query: "query text",
    //         hrefs: [
    //             "http://host1/path",
    //             "http://host2/path",
    //             ...
    //             "http://hostN/path",
    //         ],
    //         relaited: [
    //             "relaited query text 0",
    //             "relaited query text 1",
    //             ...
    //             "relaited query text N"
    //         ]
    //     }
    var result = null;
    var anchors = {
    
        getSearchQuery: function() {
            var URLObj = new URL(document.location);
            var params = URLObj.searchParams;
            var query = params.get('q');
            return query;
        },
    
        getSearchResultAnchors: function() {
            var A = null;
            A = document.getElementsByTagName("a");
            var id, len = A.length;
            var res = [];
            for(id = 0; id < len; id++) {
                var a = A[id];
                if (this.isEnabledChildTags(a, ["H3", "BR", "DIV"]))
                    res.push(a);
            }
            return res;
        },
    
        isEnabledChildTags: function(node, tagNames) {
            var cnt = 0;
            var id, len = node.childNodes.length;
            for (id = 0; id < len; id++) {
                var childNode = node.childNodes[id];
                if (childNode.tagName == tagNames[cnt]) {
                    cnt += 1;
                    if (cnt == tagNames.length)
                        return true;
                }
            }
            return false;
        },
    
        getRelaitedAnchors: function() {
            var A = null;
            A = document.getElementsByTagName("a");
            var id, len = A.length;
            var res = [];
            for(id = 0; id < len; id++) {
                if (A[id].parentNode.tagName == "P")
                    res.push(A[id]);
            }
            return res;
        },
    
        get: function() {
    
            var res = {
                query: "",
                hrefs: [],
                relaited: []
            };
    
            res.query = this.getSearchQuery();
    
            var A = this.getSearchResultAnchors();
            var id, len = A.length;
            for(id = 0; id < len; id++) {
                res.hrefs.push(A[id].href);
            }
    
            var A = this.getRelaitedAnchors();
            var id, len = A.length;
            for(id = 0; id < len; id++) {
                res.relaited.push(A[id].innerText);
            }
    
            return res;
        }
    };
    result = anchors.get();
    Можно использовать режим headless
     
    #2 ckpunmkug, 10 Jun 2019
    Last edited: 10 Jun 2019
    mail156 likes this.