From 7958ea8993e73c3c07854a0d8bccc606c3207249 Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Sun, 29 Nov 2026 00:47:45 +0000 Subject: [PATCH] docs: add docs/ with an index Co-Authored-By: Claude Opus 5.5 --- docs/api.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ docs/index.md | 9 +++++++ 2 files changed, 81 insertions(+) create mode 100644 docs/api.md create mode 100644 docs/index.md diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..e78fbfd --- /dev/null +++ b/docs/api.md @@ -0,0 +1,72 @@ +# API reference + +All names are in the `pywikihow` package. The exceptions are in `pywikihow.exceptions`. + +## `HowTo(url="http://www.wikihow.com/Special:Randomizer", lazy=True)` + +One WikiHow article. With `lazy=True`, the object downloads and parses the page at the first access to `url`, `title`, `intro` or `steps`. With `lazy=False`, it parses the page in the constructor. + +| Member | Value | +| :--- | :--- | +| `url` | The article URL | +| `title` | The article title | +| `intro` | The article intro text | +| `steps` | A list of `HowToStep` objects, in order | +| `n_steps` | The number of steps. It does not start a parse, so it is `0` until the page is parsed | +| `summary` | The title, then one line ` - ` for each step | +| `as_dict()` | A dict with the keys `title`, `url`, `intro`, `n_steps` and `steps` | +| `print(extended=False)` | Prints `summary`. With `extended=True`, prints the title, the intro and each step with its description | + +## `HowToStep` + +One step of an article. + +| Member | Value | +| :--- | :--- | +| `number` | The step number | +| `summary` | The short text of the step | +| `description` | The long text of the step | +| `picture` | The URL of the step illustration, or `None` | +| `part` | The name of the parent part, for an article that divides its steps into parts | +| `title` | The step title | +| `as_dict()` | A dict with the keys `number`, `summary`, `description`, `picture`, `part` and `title` | +| `print(extended=False)` | Prints ` - `. With `extended=True`, also prints the description | + +## Search and random lookup + +| Function | Result | +| :--- | :--- | +| `RandomHowTo(lang="en")` | A `HowTo` for a random article | +| `WikiHow.search(search_term, max_results=-1, lang="en")` | A generator of `HowTo` objects. A value of `max_results` below 1 gives all results | +| `search_wikihow(query, max_results=10, lang="en")` | A list of `HowTo` objects | + +Search skips each result page that it cannot parse. + +## Languages + +The `lang` argument selects a WikiHow site from `WikiHow.lang2url`. The functions use only the part before the first `-` and change it to lowercase, so `pt-PT` selects `pt`. The keys are: `en`, `es`, `pt`, `it`, `fr`, `ru`, `de`, `zh`, `nl`, `cz`, `id`, `jp`, `hi`, `th`, `ar`, `ko`, `tr` and `vn`. + +## Exceptions + +| Exception | Cause | +| :--- | :--- | +| `UnsupportedLanguage` (a `ValueError`) | The `lang` value is not a key of `WikiHow.lang2url` | +| `ParseError` (a `RuntimeError`) | The page does not have the expected WikiHow structure, for example a page that does not exist | + +## Network and cache + +Each page request goes through a `requests_cache` session in memory. A cached page expires after one hour. + +## Example + +This is `examples/step_pictures.py`. It needs network access to WikiHow, and its output is not shown here. + +```python +from pywikihow import HowTo + +how_to = HowTo("https://www.wikihow.com/Tie-a-Tie") + +for step in how_to.steps: + if step.picture: + print(step.number, step.summary, "->", step.picture) +``` diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..2d4b8cc --- /dev/null +++ b/docs/index.md @@ -0,0 +1,9 @@ +# PyWikiHow documentation + +PyWikiHow is an unofficial Python API for WikiHow. It scrapes a WikiHow page with BeautifulSoup and returns the structured article data. It also supports search and random-article lookup. + +For installation and usage examples, read the [README](../README.md). + +| Page | Contents | +| :--- | :--- | +| [API reference](api.md) | The `HowTo` and `HowToStep` classes, search and random lookup, languages and exception types. |