duckpy
v3.2.0
pip install -U duckpy
pip install -U git+https://github.com/AmanoTeam/duckpy
sudo apt install python3-duckpy
from duckpy import Client
client = Client ()
results = client . search ( "Python Wikipedia" )
# Prints first result title
print ( results [ 0 ]. title )
# Prints first result URL
print ( results [ 0 ]. url )
# Prints first result description
print ( results [ 0 ]. description )
AsyncClient
类中提供了异步版本 import asyncio
from duckpy import AsyncClient
client = AsyncClient ()
async def get_results ():
results = await client . search ( "Python Wikipedia" )
# Prints first result title
print ( results [ 0 ]. title )
# Prints first result URL
print ( results [ 0 ]. url )
# Prints first result description
print ( results [ 0 ]. description )
loop = asyncio . get_event_loop ()
loop . run_until_complete ( get_results ())
Python (programming language) - Wikipedia
https://en.wikipedia.org/wiki/Python_(programming_language)
Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991...
您还可以根据需要设置代理或设置自定义用户代理字符串。
DuckDuckGo 可能会暂时阻止您的请求 IP 或返回空结果,特别是当您使用该库进行抓取、机器人和其他产生大量请求的内容时。这不是一个鸭子问题,可以使用代理来防止。
您可以在 Client 对象中传递一个包含代理的列表,然后 duckpy 将使用这些代理来发出请求:
import duckpy
client = duckpy . Client ( proxies = [ 'http://123.45.67.89:80' , 'https://98.76.54.32:443' ])
如果您传递多个代理,则每次使用 .search() 方法时都会随机选择它们。
import duckpy
user_agents = [
"Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0" ,
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"
]
client = duckpy . Client ( default_user_agents = user_agents )
同样,如果您传递多个用户代理,则每次使用 .search() 方法时都会随机选择它们。
我们与 DuckDuckGo 或其任何子公司或其关联公司不存在任何关联、关联、授权、认可或以任何方式正式关联。 DuckDuckGo 官方网站位于 https://duckduckgo.com。