Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
Fixes #71, thanks to @cajuncooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mincka committed Feb 15, 2020
1 parent 146a984 commit 739538f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dmarchiver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
without having to deal with the API limitations.
"""

__version__ = "0.2.5"
__version__ = "0.2.6"
12 changes: 8 additions & 4 deletions dmarchiver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ class Crawler(object):

_http_headers = {
'User-Agent': _user_agent}
_login_headers = {
'User-Agent': _user_agent,
'Referer': 'https://mobile.twitter.com/login'}
_ajax_headers = {
'User-Agent': _user_agent,
'Accept': 'application/json, text/javascript, */*; q=0.01',
Expand All @@ -273,6 +276,7 @@ class Crawler(object):
_session = None

def authenticate(self, username, password, save_session, raw_output):
force_nojs = 'https://mobile.twitter.com/i/nojs_router?path=%2Flogin'
login_url = self._twitter_base_url + '/login'
sessions_url = self._twitter_base_url + '/sessions'
messages_url = self._twitter_base_url + '/messages'
Expand All @@ -299,15 +303,15 @@ def authenticate(self, username, password, save_session, raw_output):
raw_output_file = open(
'authentication-{0}.txt'.format(username), 'wb')

response = self._session.get(
login_url,
headers=self._http_headers)
response = self._session.post(
force_nojs,
headers=self._login_headers)

if raw_output:
raw_output_file.write(response.content)
raw_output_file.close()

document = lxml.html.document_fromstring(response.text)
document = lxml.html.document_fromstring(response.content)
authenticity_token = document.xpath(
'//input[@name="authenticity_token"]/@value')[0]

Expand Down

0 comments on commit 739538f

Please sign in to comment.