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。