Demo
# Demo
# 示例
import asyncio
from loguru import logger
from PicImageSearch import Network, Yandex
from PicImageSearch.model import YandexResponse
proxies = "http://127.0.0.1:1081"
# proxies = None
url = "https://raw.githubusercontent.com/kitUIN/PicImageSearch/main/demo/images/test06.jpg"
file = "../images/test06.jpg"
@logger.catch()
async def test_async() -> None:
async with Network(proxies=proxies) as client:
yandex = Yandex(client=client)
# resp = await yandex.search(url=url)
resp = await yandex.search(file=file)
show_result(resp)
def show_result(resp: YandexResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.url) # 搜索结果链接
# logger.info(resp.raw[0].origin)
logger.info(resp.raw[0].title)
logger.info(resp.raw[0].url)
logger.info(resp.raw[0].thumbnail)
logger.info(resp.raw[0].source)
logger.info(resp.raw[0].content)
logger.info(resp.raw[0].size)
logger.info("-" * 50)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(test_async())
from loguru import logger
from PicImageSearch.model import YandexResponse
from PicImageSearch.sync import Yandex as YandexSync
proxies = "http://127.0.0.1:1081"
# proxies = None
url = "https://raw.githubusercontent.com/kitUIN/PicImageSearch/main/demo/images/test06.jpg"
file = "../images/test06.jpg"
@logger.catch()
def test_sync() -> None:
yandex = YandexSync(proxies=proxies)
resp = yandex.search(url=url)
# resp = yandex.search(file=file)
show_result(resp) # type: ignore
def show_result(resp: YandexResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.url) # 搜索结果链接
# logger.info(resp.raw[0].origin)
logger.info(resp.raw[0].title)
logger.info(resp.raw[0].url)
logger.info(resp.raw[0].thumbnail)
logger.info(resp.raw[0].source)
logger.info(resp.raw[0].content)
logger.info(resp.raw[0].size)
logger.info("-" * 50)
if __name__ == "__main__":
test_sync()
// Make sure to add code blocks to your code group
- name: 前往查看
desc: 🚀 测试文件 Demo
link: https://github.com/kitUIN/PicImageSearch/blob/main/demo/cn/demo_yandex.py
bgColor: '#DFEEE7'
textColor: '#2A3344'
程序输出
2023-12-15 11:50:39.500 | INFO | __main__:show_result:34 - https://yandex.com/images/search?cbir_id=2946844%2FMpg72xWcfSYvUXil36B9Kw2240&rpt=imageview&redircnt=1702612240.1
2023-12-15 11:50:39.500 | INFO | __main__:show_result:36 - へ そ 出 し LOOK (オ リ ジ ナ ル) MIGNON WORKS (mignon) download on Z-Library
2023-12-15 11:50:39.500 | INFO | __main__:show_result:37 - https://hi.zlibrary-asia.se/book/22023894/fdf435?dsource=recommend
2023-12-15 11:50:39.500 | INFO | __main__:show_result:38 - https://avatars.mds.yandex.net/i?id=74f0b80eedc1fb1ae6920cee6a0993cabdfcb555-10929043-images-thumbs
2023-12-15 11:50:39.501 | INFO | __main__:show_result:39 - hi.zlibrary-asia.se
2023-12-15 11:50:39.501 | INFO | __main__:show_result:40 - Z-Library पुस्तकें. zlibrary-asia.se ईबुक पुस्तकालय.
2023-12-15 11:50:39.501 | INFO | __main__:show_result:41 - 1284×1801
2023-12-15 11:50:39.501 | INFO | __main__:show_result:42 - --------------------------------------------------
Редактировать эту страницу на GitHub (opens new window)
上次更新: 2024/06/30, 23:31:36