云打码 古诗文网

# 云打码  代码示例

import http.client, mimetypes, urllib, json, time, requests

class YDMHttp:
    apiurl = ‘http://api.yundama.com/api.php‘
    username = ‘‘
    password = ‘‘
    appid = ‘‘
    appkey = ‘‘

    def __init__(self, username, password, appid, appkey):  #构造方法
        self.username = username
        self.password = password
        self.appid = str(appid)
        self.appkey = appkey

    def request(self, fields, files=[]):
        response = self.post_url(self.apiurl, fields, files)
        response = json.loads(response)
        return response

    def balance(self):
        data = {‘method‘: ‘balance‘, ‘username‘: self.username, ‘password‘: self.password, ‘appid‘: self.appid, ‘appkey‘: self.appkey}
        response = self.request(data)
        if (response):
            if (response[‘ret‘] and response[‘ret‘] < 0):
                return response[‘ret‘]
            else:
                return response[‘balance‘]
        else:
            return -9001

    def login(self):
        data = {‘method‘: ‘login‘, ‘username‘: self.username, ‘password‘: self.password, ‘appid‘: self.appid, ‘appkey‘: self.appkey}
        response = self.request(data)
        if (response):
            if (response[‘ret‘] and response[‘ret‘] < 0):
                return response[‘ret‘]
            else:
                return response[‘uid‘]
        else:
            return -9001

    def upload(self, filename, codetype, timeout):
        data = {‘method‘: ‘upload‘, ‘username‘: self.username, ‘password‘: self.password, ‘appid‘: self.appid, ‘appkey‘: self.appkey, ‘codetype‘: str(codetype), ‘timeout‘: str(timeout)}
        file = {‘file‘: filename}
        response = self.request(data, file)
        if (response):
            if (response[‘ret‘] and response[‘ret‘] < 0):
                return response[‘ret‘]
            else:
                return response[‘cid‘]
        else:
            return -9001

    def result(self, cid):
        data = {‘method‘: ‘result‘, ‘username‘: self.username, ‘password‘: self.password, ‘appid‘: self.appid, ‘appkey‘: self.appkey, ‘cid‘: str(cid)}
        response = self.request(data)
        return response and response[‘text‘] or ‘‘

    def decode(self, filename, codetype, timeout):
        cid = self.upload(filename, codetype, timeout)
        if (cid > 0):
            for i in range(0, timeout):
                result = self.result(cid)
                if (result != ‘‘):
                    return cid, result
                else:
                    time.sleep(1)
            return -3003, ‘‘
        else:
            return cid, ‘‘

    def report(self, cid):
        data = {‘method‘: ‘report‘, ‘username‘: self.username, ‘password‘: self.password, ‘appid‘: self.appid, ‘appkey‘: self.appkey, ‘cid‘: str(cid), ‘flag‘: ‘0‘}
        response = self.request(data)
        if (response):
            return response[‘ret‘]
        else:
            return -9001

    def post_url(self, url, fields, files=[]):
        for key in files:
            files[key] = open(files[key], ‘rb‘);
        res = requests.post(url, files=files, data=fields)
        return res.text

######################################################################
username    = ‘zhangc‘   #普通用户
password    = ‘zc1991‘   #密码     
appid       = 7568       #开发者页面软件ID
appkey      = ‘bbb4575c2c541e5fa4fe932ce86774ef‘ #秘钥filename    = ‘./PythonHTTP调用示例/getimage.jpg‘ #解码图片路径
# 验证码类型 例:1004表示4位字母数字,不同类型收费不同。请准确填写,否则影响识别率。在此查询所有类型 http://www.yundama.com/price.html
codetype    = 1004
timeout     = 40         #超时时间
if (username == ‘username‘): #检查
    print(‘请设置好相关参数再测试‘)
else:
    yundama = YDMHttp(username, password, appid, appkey) #初始化
    uid = yundama.login();  #登陆云打码
    print(‘uid: %s‘ % uid)  #打印账户
    balance = yundama.balance(); #查余额
    print(‘balance: %s‘ % balance) #打印余额
    cid, result = yundama.decode(filename, codetype, timeout);# 开始识别,图片路径,验证码类型ID,超时时间(秒),识别结果   print(‘cid: %s, result: %s‘ % (cid, result))  #打印结果

# 古诗文网 模拟登陆 处理cookie

import requests
from lxml import etree
from urllib import request
def getCodeText(filename,codetype):
    result = None
    username    = ‘zhangc‘
    password    = ‘zc1991‘
    appid       = 7568
    appkey      = ‘bbb4575c2c541e5fa4fe932ce86774ef‘
    filename    = filename
    codetype    = codetype
    timeout     = 40
    if (username == ‘username‘):
        print(‘请设置好相关参数再测试‘)
    else:
        yundama = YDMHttp(username, password, appid, appkey)
        uid = yundama.login();
        balance = yundama.balance();
        cid, result = yundama.decode(filename, codetype, timeout);
    return result
url = ‘https://so.gushiwen.org/user/login.aspx?from=http://so.gushiwen.org/user/collect.aspx‘
session = requests.Session()    # 创建session会话,处理cookie相关反爬机制
headers = {
    ‘User-Agent‘:‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36‘
}
page_text = session.get(url=url,headers=headers).text
tree = etree.HTML(page_text)

code_src = ‘https://so.gushiwen.org‘+tree.xpath(‘//*[@id="imgCode"]/@src‘)[0]  #https://so.gushiwen.org
#request.urlretrieve(url=code_src,filename=‘./gushi.jpg‘)  #它有自己的cookie机制
code_img = session.get(url=code_src,headers=headers).content
with open(‘./gushi.jpg‘,‘wb‘) as fp:
    fp.write(code_img)

__VIEWSTATE = tree.xpath(‘//*[@id="__VIEWSTATE"]/@value‘)[0]    #动态加载
__VIEWSTATEGENERATOR = tree.xpath(‘//*[@id="__VIEWSTATEGENERATOR"]/@value‘)[0]  #动态加载
code_text = getCodeText(‘./gushi.jpg‘,1004)  #这里调用识别
data = {
    "__VIEWSTATE": __VIEWSTATE,
    "__VIEWSTATEGENERATOR": __VIEWSTATEGENERATOR,
    "from": "http://so.gushiwen.org/user/collect.aspx",
    "email": "[email protected]",
    "pwd": "zhangchen",
    "code": code_text,
    "denglu": "登录",
}

login_url = ‘https://so.gushiwen.org/user/login.aspx?from=http%3a%2f%2fso.gushiwen.org%2fuser%2fcollect.aspx‘
page_login = session.post(url=login_url,headers=headers,data=data).text #暂时不处理cookie

print(code_text) #打印解析出的验证码
with open(‘./gushi.html‘,‘w‘,encoding=‘utf-8‘) as f:
    f.write(page_login)

print(‘结束‘)

原文地址:https://www.cnblogs.com/zhangchen-sx/p/10853230.html

时间: 2024-10-11 05:29:38

云打码 古诗文网的相关文章

爬取古诗文网古诗词

#python3.6 #爬取古诗文网的诗文 import requests from bs4 import BeautifulSoup import html5lib import re import os def content(soup): b = 1 poetrydict = dict() for i in soup.find_all('a')[8:]: if i.get('href'): url = '%s%s' % ("https://so.gushiwen.org/",i.

爬虫_古诗文网(队列,多线程,锁,正则,xpath)

1 import requests 2 from queue import Queue 3 import threading 4 from lxml import etree 5 import re 6 import csv 7 8 9 class Producer(threading.Thread): 10 headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Geck

云转码视频系统

91flv视频播放系统    随着视频分享站点的兴起,以及智能手机的流行,需要进行大量的离线视频转码工作,以适应异构网络和多终端环境的需要,为此我们在2009年着手开发视频转码平台(将各种格式的视频文件转换成H264编码的mp4,3GP文件),并于2010年6月推出2.0版,2011年4月成功推出2.5.1版,推出后不断吸收用户意见,持续改进,更新至现在的2.5.3版本.于此同时我们结合云计算的MapReduce分布式计算思想,构造一个多台机器协同工作的云转码平台,达到超快速乃至准实时转码的目的

阿里云推荐码助您赚翻双11,全面支持折扣订单,更有10%返利!

阿里云推荐码助力双"11"重磅升级 全面支持折扣订单,更有10%返利 双11的折扣,推荐码的返利,不容错过 点击了解详情:http://www.aliyun.com/act/aliyun/yunma.html 简单二步轻松获返利 第一步:领取推荐码 http://www.aliyun.com/act/aliyun/yunma.html 第二步:亲可以通过微信.微博.贴吧.论坛.qq等一切渠道进行推广分享你的推荐码(阿里云官网及阿里云论坛除外) 推荐码返利活动规则: 1. 分享推荐码给好

阿里云推荐码已经无效了,想优惠就用阿里云幸运券吧

在阿里云后台看到阿里云推荐码现在已经无效了,申请延期也失败,看来阿里云推荐码正式停止使用了.买阿里云服务器等产品想要获得优惠的话,就只能用阿里云幸运券了.福利吧之前分享的阿里云推荐码已经停止使用了,站长买阿里云服务器想优惠的话,就用阿里云最新优惠券:阿里云幸运券. 阿里云推荐码 urssg8 已经显示无效: 站长们想要优惠付款的话,就使用阿里云幸运券吧,可以获得随机优惠金额,还能抽奖.买阿里云ECS云服务器的站长,直接领取ECS云服务器幸运券即可. 我有几张阿里云幸运券分享给你,用券购买或者升级

分享阿里云推荐码 IC1L2A,购买服务器可以直接打9折

阿里云推荐码为:IC1L2A 阿里云还是不错滴

云服务器ECS优惠券 阿里云 ecs 5折优惠码 阿里云5折优惠码 阿里云5折推荐码 阿里云优惠码 阿里云的5折优惠券 阿里云服务器购买优惠码 服务器购买优惠码

阿里云代金券 | 阿里云优惠券云服务器ECS,就是阿里云服务器,大家一定要清楚.云服务器ECS优惠券 官方领取优惠页面:https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=s306eooi&utm_source=s306eooi 简介:云服务器ECS,就是阿里云服务器,大家一定要清楚.常用的一般都是阿里云服务器,只需在 云服务器ECS 上面点击立即领券,就领取到了阿里云服务器的幸运券,在购买阿里云服

古诗文网站的网络爬虫编写方式,通过网络爬虫抓去内容

1. 以下就是古诗文网站的爬虫代码,请看: # encoding:utf-8 import requests import re import json     def parse_page(url):     # 1.请求网站     headers = {         "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome

requests利用selenium,代理Ip,云打码,验证码抠图操作 爬取搜狗微信公众号内容

import requests from lxml import etree import time import json import random from dama import yundama from selenium import webdriver from PIL import Image #处理图片包 import pymysql import re from requests.exceptions import ConnectionError #==============