Document

Header snippet

Python Google 图片反向搜索命令行

安装依赖

pip install --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple requests webbrowser

使用说明

python Google_image_reverse_search.py 图片路径

代码

#!/usr/bin/env python
# WARNING: I DON'T KNOW PYTHON AT ALL, THIS MAY BE GRUESOME AND IDIOTIC

import sys
filePath = sys.argv[-1]

print("opening: ", filePath)

import requests

searchUrl = 'http://www.google.com/searchbyimage/upload'
multipart = { 'encoded_image': (filePath, open(filePath, 'rb')), 'image_content': ''}
response  = requests.post(searchUrl, files=multipart, allow_redirects=False)
fetchUrl  = response.headers['Location']

print("found: ", fetchUrl)

def open_in_browser(url):
	print("opening on browser...")
	import webbrowser
	webbrowser.open(url, new=2)

open_in_browser(fetchUrl)
exit(0)
posted @ 2020-03-08 20:50  codworm  阅读(363)  评论(0编辑  收藏  举报
Document

Footer snippet