API:Backlinks/zh

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page API:Backlinks and the translation is 44% complete.

Other languages:
English • ‎dansk • ‎español • ‎polski • ‎русский • ‎العربية • ‎中文 • ‎日本語
MediaWiki版本: 1.9

GET request to list pages which link to a certain page.

API文档


(main | query | backlinks)
  • This module requires read rights.
  • This module can be used as a generator.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Find all pages that link to the given page.

Parameters:
bltitle

Title to search. Cannot be used together with blpageid.

blpageid

Page ID to search. Cannot be used together with bltitle.

Type: integer
blcontinue

When more results are available, use this to continue.

blnamespace

The namespace to enumerate.

Values (separate with | or alternative): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 486, 487, 828, 829, 1198, 1199, 2300, 2301, 2302, 2303, 2600, 5500, 5501
To specify all values, use *.
bldir

The direction in which to list.

One of the following values: ascending, descending
Default: ascending
blfilterredir

How to filter for redirects. If set to nonredirects when blredirect is enabled, this is only applied to the second level.

One of the following values: all, redirects, nonredirects
Default: all
bllimit

How many total pages to return. If blredirect is enabled, the limit applies to each level separately (which means up to 2 * bllimit results may be returned).

No more than 500 (5,000 for bots) allowed.
Type: integer or max
Default: 10
blredirect

If linking page is a redirect, find all pages that link to that redirect as well. Maximum limit is halved.

Type: boolean (details)

示例

GET 请求

List backlinks to the philosophy page.

响应

{
    "batchcomplete": "",
    "continue": {
        "blcontinue": "1|987",
        "continue": "-||"
    },
    "query": {
        "backlinks": [
            {
                "pageid": 12,
                "ns": 0,
                "title": "Anarchism"
            },
            {
                "pageid": 128,
                "ns": 1,
                "title": "Talk:Atlas Shrugged"
            },
            {
                "pageid": 336,
                "ns": 0,
                "title": "Altruism"
            },
            ...
        ]
    }
}

示例代码

get_backlinks.py

#!/usr/bin/python3

"""
    get_backlinks.py

    MediaWiki Action API Code Samples
    Demo of `API:Backlinks` module: Get request to list pages which
    link to a certain page.
    MIT license
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action":"query",
    "format":"json",
    "list":"backlinks",
    "bltitle":"philosophy"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA)

重定向

在上面的示例中,仅会返回指向哲学页面的直接链接。 When blredirect is set, the response will include any pages which backlink to redirects for the value in bltitle.

These redirected backlinks are treated as separate groups within the response hierarchy, one level down from the redirect itself.

The limit set in bllimit applies separately to each level of the response, so bllimit=25 would return up to 25 direct backlinks, and up to 25 backlinks within each individual redirect.

In addition, using blcontinue when a redirect was in the response will return more second-level backlinks, before finally moving on to more direct backlinks, once all the backlinks for a redirect have been returned in full.

可能的错误

代码 信息
blbadcontinue 无效继续参数。您应该传递由之前查询返回的原始值。

参见