不幸的是,不是從Python中的上下文(或瀏覽器之外的任何東西)內遍歷一個JavaScript相關的網站一個很好的辦法。即使你將python-spidermonkey與其他形式的Javascript搭配使用(也許pyV8),這些橋樑本身並不能模擬DOM。因此任何處理UI交互的Javascript都不會起作用。
但是,如果,你希望登錄到不依賴於JavaScript,然後遍歷該網站的網站是完全有可能的。我的建議是使用Kenneth Reitz的requests模塊。你可以做類似如下:
import requests
# To handle logins you'll most likely need to maintain a session
# if the site you login to usually expects a human
s = requests.session() # starts a session
# Next you want to login to the site
s.post("http://somesite.com/login", data={"u": "username", "p": "password"})
# Now you're logged in and you can do anything you want
# using the session instance
response_data = s.get("http://somesite.com/awesome-page-id-like-to-grab")
# Do something with the response data ...
my_response_parsing_function(response_data.content)
還有其他的方法來做到這一點涉及Python標準庫,但請求處理所有的事實真相的東西。