如何绕过微信图片的防盗链

具体实现原来可以参考这个链接: https://www.zhihu.com/question/35044484

下面给个Django下的实现代码:

@csrf_exempt
def image_proxy(request):
    img = request.GET.get('img')
    headers = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36',
    }
    status = 0
    try:
        r = requests.get(
            img,
            headers=headers)
    except ConnectionError, ConnectTimeout:
        status = 1
    if status == 1:
        return ''
    response = HttpResponse(r.content, content_type='image/jpeg')
    return response

url.py

url(r'^spider-api/image-proxy/$', image_proxy),

访问方法,url:

http://127.0.0.1:8001/spider-api/image-proxy/?img=https://mmbiz.qpic.cn/mmbiz_png/WliaoSKPrpSPqGrhMmQK8MwKR6AZ7qDDy2JtSxRjk3ZUke41PUGP6RoaibzIgxw8ey5cejb5FzkplhgGd48oOxAg/640
Continue Reading

获取网页中所有的文字

# encoding=utf8
 
import sys
 
reload(sys)
 
sys.setdefaultencoding('utf8')
 
import re
import requests
from bs4 import BeautifulSoup
 
 
html = requests.get('https://mp.weixin.qq.com/s?src=11&timestamp=1533887718&ver=1051&signature=Xszdx5nmmHyebcH0MXxyHi7-jDwGoNDUDXCHJzPVic68tXGRSTiM3CStUDfSR*aALaC3nK3Ez4e33uLR5ir1pLgy3vEvWXWOvVXgAbsXMn5fB-HWboOW26GH*KMRVhgX&new=1')
soup = BeautifulSoup(html.text, "html5lib")
data = soup.findAll(text=True)
 
 
def visible(element):
    if element.parent.name in ['style', 'script', '[document]', 'head', 'title']:
        return False
    elif re.match('<!--.*-->', str(element.encode('utf-8'))):
        return False
    return True
 
 
result = filter(visible, data)
 
with open('res.txt', "w+") as p:
    for i in result:
        print(str(i))
        p.write(str(i))
 
 
print list(result)
Continue Reading

Broadlink-e-control-db-dump bug fix

This script will “parse” the broadlink e-Control Android application **rmt.db database** and dump the IR / RF codes (in HEX format) for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub.

这个东西在处理逻辑上有bug,如果出现查询为空的情况,就挂了。

Continue Reading

domoticz 检测设备在线状态

最近又开始折腾语音控制相关的东西,比较郁闷的是家里的电视机和机顶盒貌似并不能直接接入。于是每次想要开关电视和机顶盒就需要知道设备的在线状态。那么为了获取在线状态,最简单的办法就是创建一个开关,标记当前设备的状态:

设备类型如下:

如果不能手工添加开关,现在硬件页面创建一个Dummy类型的设备,新增加的开关类型为Dummy。

Continue Reading