requests

 

 

 

POST

import requests


url = 'https://accounts.douban.com/login'
# 封装请求参数
data = {
    
}
# 自定义请求头信息
headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 '
                  '(KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
}
response = requests.post(url=url, data=data, headers=headers)
page_text = response.text

 

Cookies

import requests

session = requests.session()

login_url = 'https://accounts.douban.com/login'
data = {

}

headers = {

}
# 使用session发送请求,目的是为了将session保存该次请求中的cookie
# 下次使用session对象发送请求时,会自动携带cookies
login_response = session.post(url=login_url, data=data, headers=headers)

# 对个人主页发起请求(用session), 获取响应页面数据
personal_url = ''
response = session.get(url=personal_url, headers=headers)

 

代理

import requests
# 免费代理ip提供网站:
#    # http://www.goubanjia.com/
#    # 西祠代理
#    # 快代理

url = ''

proxy = {
    'http': '11.23.56.58:1596',
    # 或 'https': '11.23.56.58:1596',与url http协议对应
}
headers = {}
response = requests.get(url=url, proxies=proxy, headers=headers)

 

图片验证码处理

import requests
"""
1、 对携带验证码的页面进行数据抓取
2、 将页面中验证码下载到本地
3、 将验证码图片交给三方平台,返回图片上的数据
        云打码平台:
            1、官网注册普通用户和开发者用户
            2、登录开发者用户
                - 示例代码的下载(开发文档-调用示例及最新DLL-Python调用示例)
                - 创建一个软件(我的软件-添加新的软件-输入名称-提交)
            3、使用示例中的代码,进行修改
"""
# from xml import etree
from lxml import etree
# 1、对携带验证码的页面进行数据抓取
url = ''
headers = {}

page_text = requests.get(url=url, headers=headers).text

# 2、 将页面中验证码下载到本地
tree = etree.HTML(page_text)
codeImg_url = tree.xpath('')

code_img = requests.get(url=codeImg_url, headers=headers).content
with open('code.png', 'wb', encoding='utf-8') as f:
    f.write(code_img)

# 获取captcha_id


# 处理图片,获取文字


# 登录操作

 

posted @ 2018-11-20 00:48  web123  阅读(92)  评论(0)    收藏  举报