-
Notifications
You must be signed in to change notification settings - Fork 13
/
search.py
111 lines (97 loc) · 3.3 KB
/
search.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# 搜索测试
# from duckduckgo_search import DDGS
import pyvirtualcam
import cv2
import base64
import numpy as np
from PIL import Image
from io import BytesIO
import requests
import time
from urllib.parse import quote
from duckduckgo_search import DDGS
width = 730 # 图片宽度
height = 470 # 图片高度
proxies = {"http": "socks5://127.0.0.1:10806", "https": "socks5://127.0.0.1:10806"}
# with DDGS(proxies="socks5://localhost:10806", timeout=20) as ddgs:
# for r in ddgs.text(
# "明天广州天气",
# region="cn-zh",
# timelimit="d",
# backend="api",
# max_results=1,
# ):
# print(r["body"])
# with DDGS(proxies="socks5://localhost:10806", timeout=20) as ddgs:
# keywords = "华为手机"
# ddgs_videos_gen = ddgs.videos(
# keywords,
# region="wt-wt",
# safesearch="off",
# timelimit="w",
# resolution="high",
# duration="medium",
# max_results=1,
# )
# for r in ddgs_videos_gen:
# print(r)
with DDGS(proxies="socks5://localhost:10806", timeout=20) as ddgs:
keywords = "华为手机"
ddgs_images_gen = ddgs.images(
keywords,
region="cn-zh",
safesearch="off",
size=None,
color="color",
type_image=None,
layout=None,
license_image=None,
max_results=3,
)
for r in ddgs_images_gen:
print(r)
with DDGS(proxies="socks5://localhost:10806", timeout=20) as ddgs:
keywords = '炭治郎'
r = ddgs.translate(keywords,from_="zh-Hans", to="en")
print(r)
# with DDGS(proxies="socks5://localhost:10806", timeout=20) as ddgs:
# with pyvirtualcam.Camera(width, height, device="OBS Virtual Camera", fps=20) as cam:
# print(f"输出虚拟摄像头: {cam.device}")
# keywords = "华为" # Ultraman Huawei phones 华为手机
# ddgs_images_gen = ddgs.images(
# keywords,
# region="wt-wt",
# safesearch="off",
# size="Medium",
# color="color",
# type_image=None,
# layout="Wide",
# license_image=None,
# max_results=10,
# )
# for r in ddgs_images_gen:
# imgUrl = r["image"]
# print(f"图片地址:{imgUrl},keywords:{keywords}")
# response = requests.get(imgUrl, proxies=proxies)
# img_data = response.content
# # 读取二进制字节流
# img = Image.open(BytesIO(img_data))
# img = img.resize((width, height), Image.LANCZOS)
# # 字节流转换为cv2图片对象
# image = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
# # 转换为RGB:由于 cv2 读出来的图片默认是 BGR,因此需要转换成 RGB
# image = image[:, :, [2, 1, 0]]
# cam.send(image)
# cam.sleep_until_next_frame()
# time.sleep(600)
# def baidu_search(query):
# url = "https://www.baidu.com/s"
# params = {"wd": query} # 将查询关键字作为参数传入URL中
# response = requests.get(url, params=params)
# if response.status_code == 200:
# return response.text
# else:
# print("Error occurred while searching on Baidu.")
# # 测试函数
# result = baidu_search("Python")
# print(result)