架构python问题

2024-03-28 23:08:13 发布

您现在位置:Python中文网/ 问答频道 /正文

创建分布式爬虫python应用程序。它由一个主服务器和将在客户端服务器上运行的相关客户端应用程序组成。客户端应用程序的目的是在目标站点上运行,以提取特定的数据。客户机需要深入到站点内部,在多个级别的表单后面,因此每个客户机都是专门针对给定站点的。在

每个客户端应用程序看起来都像

main:

parse initial url

call function level1 (data1)

function level1 (data)
 parse the url, for data1
 use the required xpath to get the dom elements
 call the next function
 call level2 (data)


function level2 (data2)
 parse the url, for data2
 use the required xpath to get the dom elements
 call the next function
 call level3

function level3 (dat3)
 parse the url, for data3
 use the required xpath to get the dom elements
 call the next function
 call level4

function level4 (data)
 parse the url, for data4
 use the required xpath to get the dom elements

 at the final function.. 
 --all the data output, and eventually returned to the server        
 --at this point the data has elements from each function...

我的问题: 如果 子函数受当前函数的影响而变化,我正在努力计算 找出最好的方法。在

^{pr2}$

我用python编写解析脚本。。在

所以。。。如有任何想法/意见,将不胜感激。。。在

我可以谈得更详细,但不想让任何人厌烦!!在

谢谢!在

汤姆


Tags: theto应用程序url客户端fordataget
3条回答

看看multiprocessing类。它允许您设置一个工作队列和一个工作人员池,当您解析页面时,您可以派生出由单独进程完成的任务。在

这听起来像是Hadoop上MapReduce的一个用例。在

Hadoop Map/Reduce是一个软件框架,它可以方便地编写应用程序,以可靠、容错的方式在大型集群(数千个节点)上并行处理大量数据(数TB的数据集)。在您的情况下,这将是一个较小的集群。

Map/Reduce作业通常将输入数据集拆分为独立的块,这些块由Map任务以完全并行的方式处理。在

你提到过

i've thought of breaking the app up in a manner that would allow the master to essentially pass packets to the client boxes, in a way to allow each client/function to be run directly from the master.

据我所知,你希望一台主机(box)充当主机,并拥有运行其他功能的客户机。例如,可以运行main()函数并解析其上的初始URL。好的一点是,您可以在不同的机器上并行处理这些url的任务,因为它们看起来彼此独立。在

因为level4依赖于level3,level3依赖于level2。。依此类推,您可以通过管道将每个输出传递到下一个,而不是从每个输出中调用一个。在

在下面的教程中,我将推荐如何做这件事

希望这有帮助。在

查看scrapy包。它将允许您轻松创建“客户端应用程序”(又称爬虫、蜘蛛或爬虫)深入网站。在

brool和{a3}都对项目的分布式部分有很好的建议。在

相关问题 更多 >