您可以在 URL 上使用纯 HTML 版本的 DDG https://duckduckgo.com/html/?q=
。这样您就可以使用纯requests
/beautifulsoup
方法并轻松获取所有页面:
import requests
from bs4 import BeautifulSoup
q = '"centre of intelligence"'
url = 'https://duckduckgo.com/html/?q={q}'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0'}
soup = BeautifulSoup(requests.get(url.format(q=q), headers=headers).content, 'html.parser')
while True:
for t, a, s in zip(soup.select('.result__title'), soup.select('.result__a'), soup.select('.result__snippet')):
print(t.get_text(strip=True, separator=' '))
print(a['href'])
print(s.get_text(strip=True, separator=' '))
print('-' * 80)
f = soup.select_one('.nav-link form')
if not f:
break
data = {}
for i in f.select('input'):
if i['type']=='submit':
continue
data[i['name']] = i.get('value', '')
soup = BeautifulSoup(requests.post('https://duckduckgo.com' + f['action'], data=data, headers=headers).content, 'html.parser')
印刷:
Centre Of Intelligence - Home | Facebook
https://www.facebook.com/Centre-Of-Intelligence-937637846300833/
Centre Of Intelligence . 73 likes. Non-profit organisation. Facebook is showing information to help you better understand the purpose of a Page.
--------------------------------------------------------------------------------
centre of intelligence | English examples in context | Ludwig
https://ludwig.guru/s/centre+of+intelligence
(Glasgow was "the centre of the intelligence of England" according to the Grand Duke Alexis, who attended the launch of his father Tsar Alexander II's steam yacht there in 1880).
--------------------------------------------------------------------------------
Chinese scientists who studied bats in Aus at centre of intelligence ...
https://www.youtube.com/watch?v=UhcFXXzf2hc
Intelligence agencies are looking into two Chinese scientists in a bid to learn the true origin of COVID-19. Two Chinese scientists who studied live bats in...
--------------------------------------------------------------------------------
... and so on.