clips / pattern

Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.
https://github.com/clips/pattern/wiki
BSD 3-Clause "New" or "Revised" License
8.75k stars 1.58k forks source link

Facebook scraping error - 'TypeError: tuple indices must be integers, not str' #239

Closed leewenjie closed 6 years ago

leewenjie commented 6 years ago

Hi,

This error is regarding the facebook scaping feature. When I run the following example codes...

`` from pattern.web import Facebook, NEWS, COMMENTS, LIKES

fb = Facebook(license='own_generated_code_from_developers.facebook.com/tools/explorer/') me = fb.profile(id=None) # user info dict

for post in fb.search(me['id'], type=NEWS, count=100): print repr(post.id) print repr(post.text) print repr(post.url)

if post.comments > 0:
    print '%i comments' % post.comments 
    print [(r.text, r.author) for r in fb.search(post.id, type=COMMENTS)]
if post.likes > 0:
    print '%i likes' % post.likes 
    print [r.author for r in fb.search(post.id, type=LIKES)]

``

I get the following error... for post in fb.search(me['id'], type=NEWS, count=100): TypeError: tuple indices must be integers, not str

Can anyone help on this?

leewenjie commented 6 years ago

Ownself question, ownself answer.

It works now, use this instead.

`` for post in fb.search(me[0], type=NEWS, count=100): print repr(post.id) print repr(post.text) print repr(post.url)

if post.comments > 0:
    print '%i comments' % post.comments 
    print [(r.text, r.author) for r in fb.search(post.id, type=COMMENTS)]
if post.likes > 0:
    print '%i likes' % post.likes 
    print [r.author for r in fb.search(post.id, type=LIKES)]

``