Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] KeyError: 'href' error #2

Closed
DariuszPorowski opened this issue Mar 28, 2023 · 0 comments · Fixed by #1
Closed

[bug] KeyError: 'href' error #2

DariuszPorowski opened this issue Mar 28, 2023 · 0 comments · Fixed by #1

Comments

@DariuszPorowski
Copy link
Contributor

DariuszPorowski commented Mar 28, 2023

If html output contains namespace e.g. <a xlink:href="./foo/bar/"> then file['href'] from loop:

throw

ERROR    -  Error building page 'README.md': 'href'
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.10/x64/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/mkdocs/commands/build.py", line 329, in build
    _build_page(file.page, config, doc_files, nav, env, dirty)
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/mkdocs/commands/build.py", line 234, in _build_page
    output = config.plugins.run_event('post_page', output, page=page, config=config)
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/mkdocs/plugins.py", line 520, in run_event
    result = method(item, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/mkdocs_exclude_unused_files/plugin.py", line 62, in on_post_page
    self.asset_files.discard(str(Path(path.join(path.dirname(page.file.abs_dest_path), unquote(file['href']))).resolve()))
  File "/opt/hostedtoolcache/Python/3.10.10/x64/lib/python3.10/site-packages/bs4/element.py", line 1529, in __getitem__
    return self.attrs[key]
KeyError: 'href'

proposed solution:

for file in soup.find_all("a", {'href': True}):

it will scraping only valid links.

fix with abstraction proposed in: #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant