MediawikiSharp_API 1.0.2
See the version list below for details.
dotnet add package MediawikiSharp_API --version 1.0.2
NuGet\Install-Package MediawikiSharp_API -Version 1.0.2
<PackageReference Include="MediawikiSharp_API" Version="1.0.2" />
paket add MediawikiSharp_API --version 1.0.2
#r "nuget: MediawikiSharp_API, 1.0.2"
// Install MediawikiSharp_API as a Cake Addin #addin nuget:?package=MediawikiSharp_API&version=1.0.2 // Install MediawikiSharp_API as a Cake Tool #tool nuget:?package=MediawikiSharp_API&version=1.0.2
MediawikiSharp_API
NuGet .NET Library that help with request Wikipedia content.
To do:
- Own Wikitext parser
- GetInfoBox method
Usage
Link to class file:
Import namespace
using MediawikiSharp_API;
Initialize library:
As a parameter in constructor you type wiki language in string eg:
var mediawiki = new Mediawiki("pl");
Or leave empty to default using "en":
var mediawiki = new Mediawiki();
GetMembersOfCategory or GetMembersOfCategoryAsync
var members = mediawiki.GetMembersInCategory("Category:Medicinal plants", Mediawiki.TypeOfCatMembers.Subcats);
//or: var members = await mediawiki.GetMembersInCategoryAsync("Category:Medicinal plants", Mediawiki.TypeOfCatMembers.Subcats);
foreach (var item in members)
{
Console.WriteLine(item);
}
In both of them we will get result:
- Category:Medicinal plants by tradition
- Category:Medicinal plants of Africa
- ...
- Category:Yerba mate
- Category:Medicinal plant stubs
GetPageSections or GetPageSectionsAsync
var sections = mediawiki.GetPageSections("Bearberry", true);
foreach (var item in sections)
{
Console.WriteLine("Title: " + item.Title + ", Parrent: " + item.ParentSection + "\n");
Console.WriteLine("Content: " + item.Content + "\n");
if (item.Images.Count > 0)
{
Console.WriteLine("Images: " + item.Images.Count + "\n");
foreach (var image in item.Images)
{
Console.WriteLine(image.FileName + ":\n" + image.URL + "\n" + image.URL_Resize + "\n");
}
}
Console.WriteLine("EndSection\n");
}
The result:
"Title: Bearberry, Parrent: Bearberry
Content: [[File:Arctostaphylos-uva-ursi.JPG|thumbnail|Arctostaphylos uva-ursi]] thumb|''Arcostaphylos uva-ursi'' flowers Bearberries are three species of dwarf shrubs in the genus Arctostaphylos. Unlike the other species of Arctostaphylos (see manzanita), they are adapted to Arctic and Subarctic climates, and have a circumpolar distribution in northern North America, Asia and Europe, one with a small highly disjunctive population in Central America. thumb|150px|right|Common bearberry from ''ThomĂc Flora von Deutschland, Ă-sterreich und der Schweiz'' 1885
Images: 3
Arctostaphylos-uva-ursi.JPG: https://upload.wikimedia.org/wikipedia/commons/9/95/Arctostaphylos-uva-ursi.JPG
Bearberry_Flower.jpg: https://upload.wikimedia.org/wikipedia/commons/d/d8/Bearberry_Flower.jpg
Illustration_Arctostaphylos_uva-ursi0.jpg: https://upload.wikimedia.org/wikipedia/commons/f/f8/Illustration_Arctostaphylos_uva-ursi0.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Illustration_Arctostaphylos_uva-ursi0.jpg/150px-Illustration_Arctostaphylos_uva-ursi0.jpg"
GetImagesURL or GetImagesURLAsync
var images = mediawiki.GetImagesURL("Bearberry");
foreach (var image in images)
{
Console.WriteLine(image.FileName + ":\n" + image.URL + "\n");
}
The result:
Arctostaphylos-uva-ursi.JPG: https://upload.wikimedia.org/wikipedia/commons/9/95/Arctostaphylos-uva-ursi.JPG
Bearberry_Flower.jpg: https://upload.wikimedia.org/wikipedia/commons/d/d8/Bearberry_Flower.jpg
Illustration_Arctostaphylos_uva-ursi0.jpg: https://upload.wikimedia.org/wikipedia/commons/f/f8/Illustration_Arctostaphylos_uva-ursi0.jpg
Alpine_bearberry_in_Varrio_Nature_Reserve,_Finland.jpg: https://upload.wikimedia.org/wikipedia/commons/8/80/Alpine_bearberry_in_Varrio_Nature_Reserve,_Finland.jpg
Commons-logo.svg: https://upload.wikimedia.org/wikipedia/commons/4/4a/Commons-logo.svg
The "URL_Resize" property will be null
because we get only raw information about images. The resize can be execute manualy or will be executed automated in GetPageSections and GetPageSectionsAsync, where image will be fitted to size on Wiki page.
AdvancedRequestConstructorAndSend or AdvancedRequestConstructorAndSendAsync
This methotd allow create more advanced request or those that are not implemented in MediawikiSharp_API. Let us consider the request as default value of parameter
string request="action=query&titles=Foo&prop=info"
Request it in browser:
https://en.wikipedia.org/w/api.php?format=json&formatversion=2&action=query&titles=Foo&prop=info
We get result:
{"batchcomplete":true,"query":{"pages":[{"pageid":9132808,"ns":0,"title":"Foo","contentmodel":"wikitext","pagelanguage":"en","pagelanguagehtmlcode":"en","pagelanguagedir":"ltr","touched":"2018-07-31T15:04:55Z","lastrevid":794535609,"length":108,"redirect":true}]}}
Copy all of text, go to Visual Studio and in any place in code do this: Edit → Paste Special → Paste JSON As Classes.
public class MyJSON
{
public class Rootobject
{
public bool batchcomplete { get; set; }
public Query query { get; set; }
}
public class Query
{
public Page[] pages { get; set; }
}
public class Page
{
public int pageid { get; set; }
public int ns { get; set; }
public string title { get; set; }
public string contentmodel { get; set; }
public string pagelanguage { get; set; }
public string pagelanguagehtmlcode { get; set; }
public string pagelanguagedir { get; set; }
public DateTime touched { get; set; }
public int lastrevid { get; set; }
public int length { get; set; }
public bool redirect { get; set; }
}
}
This will safe a lot of time. Of course you can create json classes independently.
Then call the method:
var json = await mediawiki.AdvancedRequestConstructorAndSendAsync<MyJSON.Rootobject>();
var result = json.query.pages[0];
Console.WriteLine(result.contentmodel);
Console.WriteLine(result.lastrevid);
Console.WriteLine(result.length);
Console.WriteLine(result.ns);
Console.WriteLine(result.pageid);
Console.WriteLine(result.pagelanguage);
Console.WriteLine(result.pagelanguagedir);
Console.WriteLine(result.pagelanguagehtmlcode);
Console.WriteLine(result.redirect);
Console.WriteLine(result.title);
Console.WriteLine(result.touched);
with result:
wikitext
794535609
108
0
9132808
en
ltr
en
True
Foo
31.07.2018 15:04:55
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- CXuesong.MW.MwParserFromScratch (>= 0.2.1)
- Newtonsoft.Json (>= 11.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Expansed the methods.