나는 PRAW를 사용하지 않으므로 그것에 대해 잘 모르겠다.하지만 내가하고 싶은 일을한다면, 다음과 같이 할 것이다 : 로그인, modhash 저장, HTML에서 HTML 가져 오기 당신이 가고 싶은 곳 :
내가 그것을 저장할 때 어떤 CSS 나 뭔가가 빠져있는 것처럼 보이지만, 그것은 충분히 인식 할 만하다. 당신은 pprint
및 json
import requests, json
from pprint import pprint as pp2
#----------------------------------------------------------------------
def login(username, password):
"""logs into reddit, saves cookie"""
print 'begin log in'
#username and password
UP = {'user': username, 'passwd': password, 'api_type': 'json',}
headers = {'user-agent': '/u/STACKOVERFLOW\'s API python bot', }
#POST with user/pwd
client = requests.session()
r = client.post('http://www.reddit.com/api/login', data=UP)
#if you want to see what you've got so far
#print r.text
#print r.cookies
#gets and saves the modhash
j = json.loads(r.text)
client.modhash = j['json']['data']['modhash']
print '{USER}\'s modhash is: {mh}'.format(USER=username, mh=client.modhash)
#pp2(j)
return client
client = login(USER, PASSWORD)
#mod mail url
url = r'http://www.reddit.com/r/mod/about/message/inbox/'
r = client.get(url)
#here's the HTML of the page
pp2(r.text)
감사합니다 이것에 대한 많은과 함께
requests
모듈이 필요합니다. 결과를 쓰려면'pp2 (r.text, open ("path/to/local/file", "w"))'로 끝내야했습니다. – Db0도와 드리겠습니다! 그것이 당신을 위해 효과가 있다면 대답을 받아 들일 것을 잊지 마세요. – TankorSmash