question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sections and subsections treated differently, is this API or mwclient?

See original GitHub issue

Seeing issue when using page.text(section=x)

Consider following page:

== Section 1 ==
stuff

=== Subsection 1 ===
sub stuff

== Section 2 ==
stuff stuff

page.text(section=1) is

== Section 1 ==
stuff

=== Subsection 1 ===
sub stuff

page.text(section=2) is

=== Subsection 1 ===
sub stuff

Why is asking for section=1 including section=2?

Is this mwclient code issue or Mediawiki API problem?

Info: mwclient 0.8.1, python 2.6.6, Mediawiki 1.23

Considering how TOC is presented by Mediawiki, it makes sense to use floats, so sections are 1, 1.1 and 2.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
danmichaelocommented, Feb 20, 2016

True, it’s a MediaWiki thing… I think it would be confusing to make a custom implementation in mwclient.

But note that you can get helpful TOC information from prop=sections, including

mwclient.Site('en.wikipedia.org').raw_api('parse', page='Paris', prop='sections')
{
   "parse": {
      "sections": [
         {
            "index": "1", 
            "level": "2", 
            "fromtitle": "Paris", 
            "toclevel": 1, 
            "number": "1", 
            "byteoffset": 9323, 
            "line": "History", 
            "anchor": "History"
         }, 
         {
            "index": "2", 
            "level": "3", 
            "fromtitle": "Paris", 
            "toclevel": 2, 
            "number": "1.1", 
            "byteoffset": 9380, 
            "line": "Etymology", 
            "anchor": "Etymology"
         }, 
         {
            "index": "3", 
            "level": "3", 
            "fromtitle": "Paris", 
            "toclevel": 2, 
            "number": "1.2", 
            "byteoffset": 10844, 
            "line": "Origins", 
            "anchor": "Origins"
         }, 
  ………
}

Perhaps we should add a sections() method on the Page object to simplify getting that information?

0reactions
danmichaelocommented, Feb 23, 2016

Closing this issue. Feel free to open a new issue if you have ideas on how mwclient could make it easier to work with sections without breaking api compability. As mentioned, I’m considering adding .sections() to Page.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for mwclient.page - Docs
Source code for mwclient.page ... Built with Sphinx using a theme provided by Read the Docs. Read the Docs v: latest.
Read more >
get all sections separately with wikimedia api - Stack Overflow
I try to get all seperate sections of a ...
Read more >
explain xkcd talk:Community portal/Proposals
There are some suggestions on how to organize the community portal here (basically using subpages for different purposes, ...
Read more >
mwclient Documentation - Read the Docs
Mwclient is a MIT licensed client library to the MediaWiki API that should work well with both Wikimedia wikis and.
Read more >
Debian -- Software Packages in "sid", Subsection python
Software Packages in "sid", Subsection python ... python3-mwclient (0.10.1-2): MediaWiki API client in Python; python3-mwoauth (0.3.7-4) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found