taspinar / twitterscraper

Scrape Twitter for Tweets
MIT License
2.39k stars 579 forks source link

Change CLI to python script #276

Closed Frickson closed 4 years ago

Frickson commented 4 years ago

Can I request for an example of python script to get the data same as the CLI below did? (twitterscraper username --profiles --o filename.json)

edmangog commented 4 years ago

I would like to learn that too. Could anyone helps?

lapp0 commented 4 years ago

this wont have the same behavior as --profiles but if you want the info for a single username, you can do

import twitterscraper, json
from twitterscraper.main import JSONEncoder
result = twitterscraper.query.query_user_info('jack')
with open('myoutput.json', "w", encoding="utf-8") as output:
    json.dump(result, output, cls=JSONEncoder)

Please examine query.py and main.py to see the inputs for other functions and try them out!