2011-09-30 47 views
1

为了确定Quora上所有主题的列表,我决定从抓取个人资料页面开始,其中有很多主题,例如, http://www.quora.com/Charlie-Cheever/topics。我从这个页面上删除了主题,但是现在我需要从页面底部的“更多”按钮上加载的Ajax页面上抓取主题。我试图找到点击“更多”按钮时执行的JavaScript功能,但没有运气。以下是这可能是相关的HTML网页放置三个片段:如何刮掉Quora个人资料页面的“更多”部分?

<div class=\"pager_next action_button\" id=\"__w2_mEaYKRZ_more\">More</div> 
{\"more_button\": \"mEaYKRZ\"} 

\"dPs6zd5\": {\"more_button\": \"more_button\"} 

new(PagedListMoreButton)(\"mEaYKRZ\",\"more_button\",{},\"live:ld_c5OMje_9424:cls:a.view.paged_list:PagedListMoreButton:/TW7WZFZNft72w\",{}) 

请问你们的人知道“更多”按钮点击时执行的JavaScript函数的名称?任何帮助,将不胜感激:)

的Python脚本在这一点上(随后this教程)看起来是这样的:

#just prints topics followed by Charlie Cheevers from the 1st page 
#!/usr/bin/python 
import httplib2,time,re 
from BeautifulSoup import BeautifulSoup 
SCRAPING_CONN = httplib2.Http(".cache") 

def fetch(url,method="GET"): 
    return SCRAPING_CONN.request(url,method) 

def extractTopic(s): 
    d = {} 
    d['url'] = "http://www.quora.com" + s['href'] 
    d['topicName'] = s.findChildren()[0].string 
    return d 

def fetch_stories(): 
    page = fetch(u"http://www.quora.com/Charlie-Cheever/topics") 
    soup = BeautifulSoup(page[1]) 
    stories = soup.findAll('a', 'topic_name') 
    topics = [extractTopic(s) for s in stories] 
    for t in topics: 
     print u"%s, %s\n" % (t['topicName'],t['url']) 

stories = fetch_stories() 
+0

嗨阿曼,我正在做类似的事情。 您是否找到解决方案? –

回答

1

你可以看到它在你的浏览器的DOM督察事件监听器。这是一个匿名函数,看起来像这样:

function(){return typeof d!=="undefined"&&!d.event.triggered?d.event.handle.apply(l.elem,arguments):b} 

这看起来像一个困难的网站凑,你可能会考虑使用硒。