爬虫

pycharm2018  IDLE

下载requests库 http://www.python-requests.org/en/master/

 

r = requests.get(url)

 

win平台 以管理员身份运行cmd,执行

pip install requests

pip install beautifulsoup4

IDLE  requests爬虫常用语句:

import requests
r = requests.get("http://203.91.44.4:32004/Login")
r.status_code
r.text
r.encoding
r.apparent_encoding
r.content

requests.request()
requests.get(url,params=None,**kwargs)
requests.head()
requests.post()
requests.put()
requests.patch()
requests.delete()

requests.ConnectionError
requests.HTTPError
requests.URLRquired
requests.TooManyRedirects
requests.Timeout
r.raise_for_status()

使用OCR识别验证码

pip install lxml

pip install tushare

pip install baidu-aip

pip install cssselect

 

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from aip import AipOcr
>>> APP_ID = '11760004 '
>>> API_KEY = 'AwmwVQxrDFE4eXDg07A0k6qc'
>>> SECRET_KEY = 'VdI1s4gjXNlPPm1Z1c5BCj871vn4cc7Z'
>>> client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
>>> def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

>>> def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()
image = get_file_content('F:\\GetValidateCode.jpg')
SyntaxError: invalid syntax
>>> def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

>>> image = get_file_content('F:\\GetValidateCode.jpg')
>>> result = client.basicGeneral(image)
>>> options = {
        'detect_direction' : 'true',
        'language_type' : 'CHN_ENG',

}
>>> result = client.basicGeneral(image,options)
>>> print(result)
{'log_id': 291960611943065081, 'direction': 0, 'words_result_num': 1, 'words_result': [{'words': '25112'}]}

>>> for word in result['words_result']:
	print(word['words'])

	
25112
>>> 
for word in result['words_result']:
	valid = word['words']
	print(valid)

	
25112
>>> 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值