Skip to content

Commit b1c4365

Browse files
authored
Update query.py
sm-ghavami Issue taspinar#337 Fix
1 parent 0e5e269 commit b1c4365

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

twitterscraper/query.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
HEADER = {'User-Agent': random.choice(HEADERS_LIST), 'X-Requested-With': 'XMLHttpRequest'}
3333
logger.info(HEADER)
3434

35-
INIT_URL = 'https://twitter.com/search?f=tweets&vertical=default&q={q}&l={lang}'
35+
#INIT_URL = 'https://twitter.com/search?f=tweets&vertical=default&q={q}&l={lang}'
36+
INIT_URL = 'https://twitter.com/i/search/timeline?f=tweets&vertical=' \
37+
'default&include_available_features=1&include_entities=1&' \
38+
'reset_error_state=false&src=typd&max_position=-1&q={q}&l={lang}'
3639
RELOAD_URL = 'https://twitter.com/i/search/timeline?f=tweets&vertical=' \
3740
'default&include_available_features=1&include_entities=1&' \
3841
'reset_error_state=false&src=typd&max_position={pos}&q={q}&l={lang}'
@@ -98,8 +101,10 @@ def query_single_page(query, lang, pos, retry=50, from_user=False, timeout=60, u
98101
print('not using proxy')
99102
response = requests.get(url, headers=HEADER, timeout=timeout)
100103
if pos is None: # html response
101-
html = response.text or ''
102-
json_resp = None
104+
json_resp = response.json()
105+
html = json_resp['items_html'] or ''
106+
#html = response.text or ''
107+
#json_resp = None
103108
else:
104109
html = ''
105110
try:

0 commit comments

Comments
 (0)