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保留关键字冲突了
把文件名字重新命名就没问题了。