Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions ddgs/ddgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,14 @@ def extract(self, url: str, fmt: str = "text_markdown") -> dict[str, str | bytes
msg = f"Failed to fetch {url}: HTTP {resp.status_code}"
raise DDGSException(msg)

content_map: dict[str, str | bytes] = {
"text_markdown": resp.text_markdown,
"text_plain": resp.text_plain,
"text_rich": resp.text_rich,
"text": resp.text,
"content": resp.content,
}
return {"url": url, "content": content_map.get(fmt, resp.text_markdown)}
if fmt == "text_plain":
content = resp.text_plain
elif fmt == "text_rich":
content = resp.text_rich
elif fmt == "text":
content = resp.text
elif fmt == "content":
content = resp.content
else:
content = resp.text_markdown
return {"url": url, "content": content}
Loading