getFriends.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:LazyBook 作者: cfifty 项目源码 文件源码
def getFriendsList(friends, part,s):
    ID = vanity
    if(part == 1):
        index = 0;
    elif(part == 2): 
        index = 24;
    elif(part == 3):
        index = 24+36
    else:
        index = 24+36+36

    # find scrape their total number of friends
    temp = s.get('https://www.facebook.com/' + ID + '/friends')
    soup = BeautifulSoup(temp.text,"lxml")
    strainer = SoupStrainer('a',href=re.compile("fref=fr_tab"))

    # iterator over entire friends list and pull out the relevant information from 
    # the html docs that display 24 or 36 friends each
    while (index < (numFriends)): 
        if index == 0:
            temp = s.get('https://m.facebook.com/' + ID + '/friends')
            soup = BeautifulSoup(temp.text,"lxml",parse_only=strainer)
            tempLst = soup.findAll('a')
            for item in tempLst:
                friends.append(item)
            index = 24 + 36*3
        else: 
            temp = (s.get('https://m.facebook.com/' + ID + '/friends?startindex='
                + str(index)))
            soup = BeautifulSoup(temp.text,"lxml",parse_only=strainer)
            tempLst = soup.findAll('a')
            for item in tempLst:
                friends.append(item)
            index = index + 36*4
    return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号