AttributeError: module 'requests' has no attribute 'Session'
阿新 • • 發佈:2018-12-22
AttributeError: module ‘requests’ has no attribute 'Session’
#使用requests執行人人網的登入和訪問會員中心並爬取資訊 import requests import re,time #獲取可以維持會話狀態 的requests請求物件 s = requests.Session() def doLogin(): '''執行登入''' login_url = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2018106111736' data = { 'email':'**********', 'icode':'', 'origURL':'http://www.renren.com/home', 'domain':'renren.com', 'key_id':'1', 'captcha_type':'web_login', 'password':'sdfhsdihfewiuhfiuewhfifhnvxcvdsify87rey23984723894239eywidhwi', 'rkey':'aacea8a17e84b044daab0e398049d945', 'f':'http%3A%2F%2Fwww.renren.com%2F346899196', } res = s.post(login_url,data=data) print("登陸成功!") def myHome(): '''訪問會員中心並爬取資訊''' url = 'http://www.renren.com/346899196' res = s.get(url) html = res.content.decode('utf-8') #html = gzip.decompress(res.read()).decode('utf-8') print(re.findall("<title>(.*?)</title>",html)) if __name__ == "__main__": #執行登入 print("登入中...") doLogin() time.sleep(2) #訪問會員中心 myHome()
最後問題是出在檔案命名與Python保留關鍵字衝突了
把檔名字重新命名就沒問題了。