【python2.7】使用requests模块登陆豆瓣

不需要user-agent伪装就可以登陆成功,测试时间:2017-11-04

# -*- coding: utf-8 -*-
import requests
import re
from bs4 import BeautifulSoup

'''
新建一个Session实例,发送get请求,判断是否有captcha
'''

s = requests.Session()
url_login = 'https://accounts.douban.com/login'
response = s.get(url_login)
# print response.request.headers
soup = BeautifulSoup(response.text, 'html.parser')
captcha = soup.find('img', id='captcha_image')

if captcha:
    captcha_url = captcha['src']
    print captcha_url
    captcha_text = raw_input('Please input the captcha:')
    re_captcha_id = r'

你可能感兴趣的:(【python2.7】使用requests模块登陆豆瓣)