2013-06-24 36 views
0

我有一個URL的列表,並希望爲其每個網頁刮取位置對象。我所指的數據是通過在瀏覽器的控制檯中鍵入「window.location」生成的。例如,Chrome會www.github.com執行此操作會給你類似以下的輸出:如何刮取位置對象?

位置{分配:功能,取代:函數重載:函數,ancestorOrigins:DOMStringList,來源:「 https://github.com「...}

展開時,你可以看到更多信息:

Location { 
    ancestorOrigins: DOMStringList 
    assign: function() { [native code] } 
    hash: "" 
    host: "github.com" 
    hostname: "github.com" 
    href: "https://github.com/" 
    origin: "https://github.com" 
    pathname: "/" 
    port: "" 
    protocol: "https:" 
    reload: function() { [native code] } 
    replace: function() { [native code] } 
    search: "" 
    toString: function toString() { [native code] } 
    valueOf: function valueOf() { [native code] } 
    __proto__: Location 
} 

我已經使用過Python和Mechanize庫來刮過去,但是直到現在從未想過這個功能,我不知道如何繼續。任何建議都會受到歡迎。

回答

1

據我所知,你想要在所需的網頁上執行JavaScript調用。我的建議是使用一些無頭瀏覽器。我用框架做了類似的事情,名字爲PyQt4。您也可以使用PhantomJS等其他無頭網頁瀏覽器。或者你也可能會用Selenium這個工具感興趣。

+0

原來,這是非常可行的使用PhantomJS庫。我一直在玩幾分鐘,並獲得我需要的功能。 –