谁能指导我找到一个用于 javascript 代码的优秀 Python 屏幕抓取库(希望有良好的文档/教程)?我想看看那里有哪些选择,但最容易学习的是最快的结果……想知道是否有人有经验。我听说过一些关于 spidermonkey 的资料,但也许还有更好的资料?
具体来说,我使用 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 引擎和 Django 来实现它。谢谢!
最佳答案
在这些情况下,我通常做的是自动化一个实际的浏览器,并从那里获取处理过的 HTML。
编辑:
这是一个自动 InternetExplorer 导航到 URL 并在页面加载后获取标题和位置的示例。
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
关于javascript - 用于 Javascript 的 Python 爬虫?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2926338/