2016-10-30 18 views
3

ウェブページのスクロールによって生成されたコンテンツをリバースエンジニアリングしたいと考えています。問題は、URL https://www.crowdfunder.com/user/following_page/80159?user_id=80159&limit=0&per_page=20&screwrand=933にあります。 screwrandはどんなパターンにも従っていないようですので、URLを逆にすることはできません。私はスプラッシュを使用して自動レンダリングを検討しています。 Splashを使ってブラウザのようにスクロールするには?どうもありがとう!scrap-splashは無限のスクロールをどのように処理しますか?

request1 = scrapy_splash.SplashRequest('https://www.crowdfunder.com/user/following/{}'.format(user_id), 
                 self.parse_follow_relationship, 
                 args={'wait':2}, 
                 meta={'user_id':user_id, 'action':'following'}, 
                 endpoint='http://192.168.99.100:8050/render.html') 
yield request1 

request2 = scrapy_splash.SplashRequest('https://www.crowdfunder.com/user/following_user/80159?user_id=80159&limit=0&per_page=20&screwrand=76', 
                self.parse_tmp, 
                meta={'user_id':user_id, 'action':'following'}, 
                endpoint='http://192.168.99.100:8050/render.html') 
yield request2 

ajax request shown in browser console

答えて

4

カスタムレンダリングスクリプトを書くことができますページをスクロールする(http://splash.readthedocs.io/en/stable/scripting-tutorial.htmlを参照)、このような何か:

function main(splash) 
    local num_scrolls = 10 
    local scroll_delay = 1.0 

    local scroll_to = splash:jsfunc("window.scrollTo") 
    local get_body_height = splash:jsfunc(
     "function() {return document.body.scrollHeight;}" 
    ) 
    assert(splash:go(splash.args.url)) 
    splash:wait(splash.args.wait) 

    for _ = 1, num_scrolls do 
     scroll_to(0, get_body_height()) 
     splash:wait(scroll_delay) 
    end   
    return splash:html() 
end 

するレンダリングするために は、ここでは、2つの要求のためのコードですこのスクリプトは、render.htmlの代わりに「実行」エンドポイントを使用します。エンドポイント:

script = """<Lua script> """ 
scrapy_splash.SplashRequest(url, self.parse, 
          endpoint='execute', 
          args={'wait':2, 'lua_source': script}, ...) 
+0

このスクリプトを書く場所を教えてください。私はどのように私はPythonファイル –

+0

このjavascript関数を書くことができます混乱していることを意味しますこのスクリプトが終了し、いくつかのjavascriptはページに新しいコンテンツを追加する場合は、 – Milos

関連する問題