Demo
# Demo
# 示例
import asyncio
from loguru import logger
from PicImageSearch import BaiDu, Network
from PicImageSearch.model import BaiDuResponse
# proxies = "http://127.0.0.1:1081"
proxies = None
# url = "https://raw.githubusercontent.com/kitUIN/PicImageSearch/main/demo/images/test02.jpg"
url = r"images/test02.jpg" # 搜索本地图片
@logger.catch()
async def test() -> None:
async with Network(proxies=proxies) as client:
baidu = BaiDu(client=client)
resp = await baidu.search(url)
show_result(resp)
def show_result(resp: BaiDuResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.item)
if resp.same: # 存在来源结果
# logger.info(resp.raw[0].origin)
logger.info(resp.raw[0].page_title)
logger.info(resp.raw[0].title)
logger.info(resp.raw[0].abstract)
logger.info(resp.raw[0].url)
logger.info(resp.raw[0].image_src)
logger.info(resp.raw[0].img_list)
else:
logger.info(resp.similar)
logger.info("-" * 50)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(test())
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from loguru import logger
from PicImageSearch.model import BaiDuResponse
from PicImageSearch.sync import BaiDu as BaiDuSync
# proxies = "http://127.0.0.1:1081"
proxies = None
# url = "https://raw.githubusercontent.com/kitUIN/PicImageSearch/main/demo/images/test02.jpg"
url = r"images/test02.jpg" # 搜索本地图片
@logger.catch()
def test_sync() -> None:
baidu = BaiDuSync(proxies=proxies)
resp = baidu.search(url)
show_result(resp)
def show_result(resp: BaiDuResponse) -> None:
# logger.info(resp.origin) # 原始数据
logger.info(resp.item)
if resp.same: # 存在来源结果
# logger.info(resp.raw[0].origin)
logger.info(resp.raw[0].page_title)
logger.info(resp.raw[0].title)
logger.info(resp.raw[0].abstract)
logger.info(resp.raw[0].url)
logger.info(resp.raw[0].image_src)
logger.info(resp.raw[0].img_list)
else:
logger.info(resp.similar)
logger.info("-" * 50)
if __name__ == "__main__":
test_sync()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Make sure to add code blocks to your code group
- name: 前往查看
desc: 🚀测试文件Demo
link: https://github.com/kitUIN/PicImageSearch/blob/main/demo/demo_baidu.py
bgColor: '#DFEEE7'
textColor: '#2A3344'
1
2
3
4
5
2
3
4
5
程序输出,部分过长数据已省略
2022-03-27 19:51:07.502 | INFO | __main__:show_result:35 - ['cardHeader', 'similar', 'simipic']
2022-03-27 19:51:07.502 | INFO | __main__:show_result:38 - 2233娘 - 堆糖,美图壁纸兴趣社区
2022-03-27 19:51:07.503 | INFO | __main__:show_result:39 - 2233娘 - 堆糖,美图壁纸兴趣社区
2022-03-27 19:51:07.503 | INFO | __main__:show_result:40 - ['']
2022-03-27 19:51:07.503 | INFO | __main__:show_result:41 - https://graph.baidu.com/api/proxy?mroute=redirect&sec=1648381865850&seckey=09b0bd953b&u=http%3A%2F%2Fwww.duitang.com%2Falbum%2F%3Fid%3D100043582%26spm%3D2014.12553688.202.0
2022-03-27 19:51:07.503 | INFO | __main__:show_result:42 - http://img0.baidu.com/it/u=3824244960,1805978635&fm=253&app=138&f=JPEG&fmt=auto&q=75&fmt=auto&q=75?w=400&h=225
2022-03-27 19:51:07.503 | INFO | __main__:show_result:43 - [{'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=0&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img0.baidu.com/it/u=2393089883,2159545660&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=400&h=225'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=1&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img2.baidu.com/it/u=3786475797,2527201669&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=400&h=711'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=2&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img1.baidu.com/it/u=3763788455,4287288768&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=400&h=225'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=3&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img1.baidu.com/it/u=3571022921,691371778&fm=253&app=138&f=PNG&fmt=auto&q=75?w=400&h=342'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=4&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img2.baidu.com/it/u=1510379772,2126668284&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=400&h=711'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=5&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img0.baidu.com/it/u=3824244960,1805978635&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=400&h=225'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=6&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img0.baidu.com/it/u=661198801,3667830939&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=400&h=247'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=7&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img1.baidu.com/it/u=38018788,3650753422&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=400&h=320'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=8&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img2.baidu.com/it/u=1427645496,3552608932&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=400&h=566'}, {'url': 'https://graph.baidu.com/view/similardetailnew?sign=121282681ae2cc2cc82d301648381864&wd=&curWeb=0&cur=9&srcp=crs_same_webimg&carousel=28&card_key=&tn=wise&idctag=tc&sids=10004_10521_10968_10973_11031_17851_17070_18101_17200_17202_18312_19190_19162_19216_19230_19268_19280_19670_19807_20001_20011_20051_20062_20072_20091_9999_10000&gsid=&logid=3784115754&entrance=general&tpl_from=pc&pageFrom=graph_upload_pcshitu', 'imgSrc': 'http://img2.baidu.com/it/u=1838712001,1038220363&fm=253&app=138&f=PNG&fmt=auto&q=75?w=400&h=363'}]
2022-03-27 19:51:07.512 | INFO | __main__:show_result:46 - --------------------------------------------------
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
上次更新: 2022/03/27, 20:47:51