【发布时间】:2014-02-07 16:53:45
【问题描述】:
我正在尝试通过 phantomjs 递归解析网页。
例如:
WebPage:
link1,
link2,
link3,
link4,
link5
nextPage
我在这个页面上做什么:
var parsePage = function(links) {
// parse everyone link
for(var i = 0; i < posts.length; i++ )
parsePost(links[i]);
};
parsePost - 我正在从页面获取一些信息,例如通过正则表达式获取所有电子邮件和电话,这需要很长时间
但是 phantomjs (js) 是异步的,它不会等待它会解析每个人的链接,然后转到下一个页面。 它的工作原理有点不同:
- parsing page1
- parsing link1
- parsing link2
....
- parsing link5
- parsing page2
- parsing link1
....
- parsing link5
-> and just now are comes results to console from parsed page1 -> link1
.....
- parsing page3
所以我的 6gb 电脑内存需要 3 分钟 :DDD
我该如何解决这个问题?
我想这样做:
1. mb limit program memory use? ( it'll wait while some processes finished and then it continue to parse another pages ? )
2. i was trying to do like :
> page.open(link, function(... here is pageparser ( wich parsing everyone link))
and then page.close()
but pageparser takes a lot of time, so when i use page.close -> it stop pageparser process.
【问题讨论】:
-
你解决了吗?
标签: javascript parsing memory html-parsing phantomjs