有没有人可以给我一个好的Python屏幕抓取javascript代码的库(希望有好的文档/教程)?我很想看看有哪些选择,但最容易学的是最快的结果……不知道有没有人有经验。我听说过一些关于蜘蛛猴的事情,但也许还有更好的?
具体地说,我使用BeautifulSoup和Mechanize到达这里,但需要一种方法来打开javascript弹出窗口,提交数据,并下载/解析javascript弹出窗口中的结果。
<a href="javascript:openFindItem(12510109)" onclick="s_objectID="javascript:openFindItem(12510109)_1";return this.s_oc?this.s_oc(e):true">Find Item</a>我想用Google App engine和Django实现这一点。谢谢!
发布于 2010-05-28 11:08:50
在这些情况下,我通常做的是自动化一个实际的浏览器,并从那里获取处理后的HTML。
编辑:
下面是一个自动化InternetExplorer的示例,它在页面加载后导航到一个网址并抓取标题和位置。
from win32com.client import Dispatch
from ctypes import Structure, pointer, windll
from ctypes import c_int, c_long, c_uint
import win32con
import pywintypes
class POINT(Structure):
_fields_ = [('x', c_long),
('y', c_long)]
def __init__( self, x=0, y=0 ):
self.x = x
self.y = y
class MSG(Structure):
_fields_ = [('hwnd', c_int),
('message', c_uint),
('wParam', c_int),
('lParam', c_int),
('time', c_int),
('pt', POINT)]
def wait_until_ready(ie):
pMsg = pointer(MSG())
NULL = c_int(win32con.NULL)
while True:
while windll.user32.PeekMessageW(pMsg, NULL, 0, 0, win32con.PM_REMOVE) != 0:
windll.user32.TranslateMessage(pMsg)
windll.user32.DispatchMessageW(pMsg)
if ie.ReadyState == 4:
break
ie = Dispatch("InternetExplorer.Application")
ie.Visible = True
ie.Navigate("http://google.com/")
wait_until_ready(ie)
print "title:", ie.Document.Title
print "location:", ie.Document.location发布于 2010-05-28 22:37:41
我使用Python绑定到webkit来呈现基本的JavaScript和Chickenfoot,以便进行更高级的交互。有关详细信息,请参阅this webkit example。
发布于 2011-05-30 14:13:58
您也可以使用名为Spynner的“编程性web浏览器”。我发现这是最好的解决方案。相对容易使用。
https://stackoverflow.com/questions/2926338
复制相似问题