Add Support for Megalodon.jp
myano opened this issue · comments
If possible, please add support for Megalodon.jp.
I've found some snippets of code around the Internet but when I've tried doing requests with the information from these projects, I always get megalodon.jp URL as the res.url
and nothing useful in the res.headers
in the response from the server.
I've tried replicating the cookies back but sometimes I get the error from their server "「Cookieが無効な状態」" which means it is complaining about them.
Anyone have any thoughts on how to submit URLs to Megalodon.jp in Python?
I have tried to push several different pages to Megalodon.jp and found that the archive does not accept most of non-Japanese pages, so I am not sure if I am going to add it to ArchiveNow.
But if you want to add Megalodon.jp to your own copy of ArchiveNow or use a separate Python script, here is the Python code that can push pages to Megalodon.jp:
import requests
# an example page to be pushed into the archive
uri = 'http://jp-australia.com/2019/intro/'
r = requests.get('http://megalodon.jp/?url='+uri)
token = str(r.content).split('"token" value="',1)[1].split('"',1)[0]
cookies = dict(PHPSESSID=r.headers['Set-Cookie'].split('PHPSESSID=',1)[1].split(';',1)[0])
r2 = requests.post('http://megalodon.jp/pc/get_simple/decide',
data={"url":uri, "token":token},
cookies=cookies)
print 'The URI to the archived page :', str(r2.content).split('location.href = "',1)[1].split('"',1)[0]
Makes sense.
I figured it had something to do with the token but I was trying to use their http://gyo.tc/ to submit URLs and I didn't realize the importance of the cookies.
Thank you for the code. I was able to fairly easily add it as a custom handler in archivenow.
:-)
Perfect. Is your code available on Github?
@maturban I didn't put the whole fork up here, but here is a Gist of the two files I modified.
The first file is a patch file of the differences I made to index.html and the second file is the handler I wrote.
https://gist.github.com/myano/88dfdb4fea27bb632293e107a663998a