Py之wikipedia-api:wikipedia-api/Wikipedia的简介、安装、使用方法之详细攻略

Py之wikipedia-api:wikipedia-api/Wikipedia的简介、安装、使用方法之详细攻略

目录

wikipedia-api/Wikipedia的简介

wikipedia-api/Wikipedia的安装 

wikipedia-api的使用方法

1、 创建 wikipediaapi并进行查询

2、利用wikipedia获取关于Wikipedia的摘要,然后搜索了与“Barack”相关的条目列表,最后获取了纽约州(New York)的百科页面标题、URL和内容


wikipedia-api/Wikipedia的简介

Wikipedia-API是一个易于使用的Python封装,用于访问维基百科的API。它支持从维基百科提取文本、章节、链接、分类、翻译等信息。文档提供了最常见用例的代码片段。

Wikipedia是一个Python库,可以很容易地访问和解析维基百科中的数据。搜索维基百科,获取文章摘要,从页面中获取链接和图像等数据,等等。维基百科包装了MediaWiki API,这样你就可以专注于使用维基百科的数据,而不是获取它。

wikipedia-api/Wikipedia的安装 

pip install -i https://mirrors.aliyun.com/pypi/simple wikipedia-api




pip install -i https://mirrors.aliyun.com/pypi/simple wikipedia

wikipedia-api的使用方法

1、 创建 wikipediaapi并进行查询


import wikipediaapi

# 创建 Wikipedia API 的实例并设置用户代理
wiki_wiki = wikipediaapi.Wikipedia('MyProjectName (merlin@example.com)', 'en')

# 定义要查询的主题
search_topic = "Artificial Intelligence"

# 获取页面对象
page_py = wiki_wiki.page(search_topic)

# 检查页面是否存在
if page_py.exists():
    print("Page - Title:", page_py.title)
    print("Page - Summary:", page_py.summary[:60])  # 输出摘要的前60个字符
else:
    print("Page not found.")

2、利用wikipedia获取关于Wikipedia的摘要,然后搜索了与“Barack”相关的条目列表,最后获取了纽约州(New York)的百科页面标题、URL和内容

import wikipedia
res = wikipedia.summary("Wikipedia")
print(res)
# Wikipedia (/ˌwɪkɨˈpiːdiə/ or /ˌwɪkiˈpiːdiə/ WIK-i-PEE-dee-ə) is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation...

res = wikipedia.search("Barack")
print(res)
# [u'Barak (given name)', u'Barack Obama', u'Barack (brandy)', u'Presidency of Barack Obama', u'Family of Barack Obama', u'First inauguration of Barack Obama', u'Barack Obama presidential campaign, 2008', u'Barack Obama, Sr.', u'Barack Obama citizenship conspiracy theories', u'Presidential transition of Barack Obama']


ny = wikipedia.page("New York (state)")
print(ny.title)
print(ny.url)
print(ny.content)

The Wikimedia Foundation, Inc., abbreviated WMF, is an American 501(c)(3) nonprofit organization headquartered in San Francisco, California, and registered there as a charitable foundation. It is the host of Wikipedia, the seventh most visited website in the world. In addition, the foundation hosts 14 other related content projects. It supports the development of MediaWiki, the wiki software that underpins them all.
The Wikimedia Foundation was established in 2003 in St. Petersburg, Florida by Jimmy Wales, as a nonprofit way to fund Wikipedia, Wiktionary, and other crowdsourced wiki projects. (Until then, they had been hosted by Bomis, Wales's for-profit company.) The Foundation finances itself mainly through millions of small donations from Wikipedia readers, collected through email campaigns and annual fundraising banners placed on Wikipedia and its sister projects. These are complemented by grants from philanthropic organizations and tech companies, and starting in 2022, by services income from Wikimedia Enterprise.
The Foundation has grown rapidly throughout its existence. As of December 31, 2023, it has employed over 700 staff and contractors, with annual revenues of $180.2 million, annual expenses of $169 million, net assets of $255 million and a growing endowment, which surpassed $100 million in June 2021.


['Barack Obama', 'Barack Obama Sr.', 'Presidency of Barack Obama', 'Family of Barack Obama', 'Barack (disambiguation)', 'Barack (name)', 'Barack (brandy)', 'Zach Barack', 'Moisés Barack', 'Barack Obama (disambiguation)']


New York (state)
https://en.wikipedia.org/wiki/New_York_(state)
New York, sometimes called New York State, is a state in the Northeastern United States. One of the Mid-Atlantic states, it borders the Atlantic Ocean, New England, Canada and the Great Lakes. With almost 19.6 million residents, it is the fourth-most populous state in the United States and eighth-most densely populated as of 2023. New York is the 27th-largest U.S. state by area, with a total area of 54,556 square miles (141,300 km2).
New York has a varied geography. The southeastern part of the state, known as Downstate, encompasses New York City, the most populous city in the United States, with over twice the population of Los Angeles, the nation's second-largest city; Long Island, the nation's most populous island; and the suburbs and wealthy enclaves of the lower Hudson Valley. These areas are the center of the New York metropolitan area, a sprawling urban landmass, and account for approximately two-thirds of the state's population. The much larger Upstate area spreads from the Great Lakes to Lake Champlain, and includes the Adirondack Mountains and the Catskill Mountains (part of the wider Appalachian Mountains). The east–west Mohawk River Valley bisects the more mountainous regions of Upstate, and flows into the north–south Hudson River valley near the state capital of Albany. Western New York, home to the cities of Buffalo and Rochester, is part of the Great Lakes region and borders Lake Ontario and Lake Erie. Central New York is anchored by the city of Syracuse; between the central and western parts of the state, New York is dominated by the Finger Lakes, a popular tourist destination. To the south, along the state border with Pennsylvania, the Southern Tier sits atop the Allegheny Plateau, representing the northernmost reaches of Appalachia.
New York was one of the original Thirteen Colonies that went on to form the United States. The area of present-day New York had been inhabited by tribes of the Algonquians and the Iroquois Confederacy Native Americans for several thousand years by the time the earliest Europeans arrived. Stemming from Henry Hudson's expedition in 1609, the Dutch established the multiethnic colony of New Netherland in 1621. England seized the colony from the Dutch in 1664, renaming it the Province of New York. During the American Revolutionary War, a group of colonists eventually succeeded in establishing independence, and the former colony was officially admitted into the United States in 1788. From the early 19th century, New York's development of its interior, beginning with the construction of the Erie Canal, gave it incomparable advantages over other regions of the United States. The state built its political, cultural, and economic ascendancy over the next century, earning it the nickname of the "Empire State." Although deindustrialization eroded a portion of the state's economy in the second half of the 20th century, New York in the 21st century continues to be considered as a global node of creativity and entrepreneurship, social tolerance, and environmental sustainability.

The state attracts visitors from all over the globe, with the highest count of any U.S. state in 2022. Many of its landmarks are well known, including four of the world's ten most-visited tourist attractions in 2013: Times Square, Central Park, Niagara Falls and Grand Central Terminal. New York is home to approximately 200 colleges and universities, including Ivy League members Columbia University and Cornell University, and the expansive State University of New York, which is among the largest university systems in the nation. New York City is home to the headquarters of the United Nations, and it is sometimes described as the world's most important city, the cultural, financial, and media epicenter, and the capital of the world. 


== History ==


=== Native American history ===

The Native American tribes in what is now New York were predominantly Iroquois and Algonquian. 
th of them, divided roughly along Appalachia, were the Susquehannock and the Erie.
……

=== 16th century ===
In 1524, Giovanni da Verrazzano, an Italian explorer in the service of the French crown, explored the Atlantic coast of North America between the Carolinas and Newfoundland, including New York Harbor and Narragansett Bay. On April 17, 1524, Verrazzano entered New ……


=== 17th century ===

Henry Hudson's 1609 voyage marked the beginning of European involvement in the area. Sailing for the Dutch East India Company and looking for a passage to Asia, he entered the Upper New York Bay on September 11 of that year. Word of his findings encouraged Dutch merchants to explore the coast in search of profitable fur trading with local ……


=== 18th century ===


==== American Revolution ====

The Sons of Liberty were organized in New York City during the 1760s, largely in response to the oppressive Stamp Act passed by the British Parliament in 1765. The Stamp Act Congress met in the city on October 19 of that year, composed of representatives from 
……

==== Confederation period and 1790s ====
New York City was the national capital under the Articles of Confederation and Perpetual Union, the first national government. That organization was found to be inadequate, and prominent New Yorker Alexander Hamilton advocated for a new government that would include ……


=== 19th and 20th centuries ===

Transportation in Western New York was by expensive wagons on muddy roads before canals opened up the rich farmlands to long-distance traffic. Governor DeWitt Clinton promoted the Erie Canal, which connected New York City to the Great Lakes by the Hudson River, the new canal, and the rivers and lakes. Work commenced in 1817, and the Erie Canal opened ……

==== Immigration ====

Since the early 19th century, New York City has been the largest port of entry for legal immigration into the United States. In the United States, the federal government did not ……

……


== Geography ==

The state of New York covers a total area of 54,555 square miles (141,297 km2) and ranks as the 27th-largest state by size. The highest elevation in New York is Mount Marcy in 
……


=== Water ===


==== Borders ====

Among the total area of New York state, 13.6% consists of water. Much of New York's boundaries are in water, as is true for New York City: four of its five boroughs are 
……


==== Drainage ====
The Hudson River begins near Lake Tear of the Clouds and flows south through the eastern part of the state, without draining Lakes George or Champlain. Lake George empties at its ……

=== Climate ===

Under the Köppen climate classification, most of New York has a humid continental climate, though New York City and Long Island have a humid subtropical climate. Weather ……

=== Flora and fauna ===
Due to New York's relatively large land area and unique geography compared to other eastern states, there are several distinct ecoregions present in the state, many of them reduced heavily due to urbanization and other human activities: Southern Great Lakes ……


=== Regions ===

Due to its long history, New York has several overlapping and often conflicting definitions of regions within the state. The regions are also not fully definable due to the colloquial use of regional labels. The New York State Department of Economic Development provides two distinct definitions of these regions. It divides the state into ten economic regions, which approximately correspond to terminology used by residents:

The department also groups the counties into eleven regions for tourism purposes.


=== State parks ===

New York has many state parks and two major forest preserves. Niagara Falls State Park, established in 1885, is the oldest state park in the United States and the first to be created via eminent domain. In 1892, Adirondack Park, roughly the size of the state of 
……

=== National parks, monuments, and historic landmarks ===

The State of New York is well represented in the National Park System with 22 national ……

== See also ==

Index of New York (state)-related articles
Outline of New York
List of New York area codes


== Notes ==


== References ==


== Further reading ==


== External links ==
New York State Guide, from the Library of Congress
New York (state) at Curlie
 Geographic data related to New York (state) at OpenStreetMap

Process finished with exit code 0

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个处女座的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值