没人否认,维基百科是现代最令人惊叹的人类发明之一。
几年前谁能想到,匿名贡献者们的义务工作竟创造出前所未有的巨大在线知识库?维基百科不仅是你写大学论文时最好的信息渠道,也是一个极其丰富的数据源。
从自然语言处理到监督式机器学习,维基百科助力了无数的数据科学项目。
维基百科的规模之大,可称为世上最大的百科全书,但也因此稍让数据工程师们感到头疼。当然,有合适的工具的话,数据量的规模就不是那么大的问题了。
本文将介绍“如何编程下载和解析英文版维基百科”。
在介绍过程中,我们也会提及以下几个数据科学中重要的问题:
1、从网络中搜索和编程下载数据
2、运用Python库解析网络数据(HTML, XML, MediaWiki格式)
3、多进程处理、并行化处理
这个项目最初是想要收集维基百科上所有的书籍信息,但我之后发现项目中使用的解决方法可以有更广泛的应用。这里提到的,以及在Jupyter Notebook里展示的技术,能够高效处理维基百科上的所有文章,同时还能扩展到其它的网络数据源中。
本文中运用的Python代码的笔记放在GitHub,灵感来源于Douwe Osinga超棒的《深度学习手册》。前面提到的Jupyter Notebooks也可以免费获取。
GitHub链接:
https://github.com/WillKoehrsen/wikipedia-data-science/blob/master/notebooks/Downloading%20and%20Parsing%20Wikipedia%20Articles.ipynb
免费获取地址:
https://github.com/DOsinga/deep_learning_cookbook
编程搜索和下载数据
任何一个数据科学项目第一步都是获取数据。我们当然可以一个个进入维基百科页面打包下载搜索结果,但很快就会下载受限,而且还会给维基百科的服务器造成压力。还有一种办法,我们通过dumps.wikimedia.org这个网站获取维基百科所有数据的定期快照结果,又称dump。
用下面这段代码,我们可以看到数据库的可用版本:
import requests# Library for parsing HTMLfrom bs4 import BeautifulSoupbase_url = 'https://dumps.wikimedia.org/enwiki/'index = requests.get(base_url).textsoup_index = BeautifulSoup(index, 'html.parser')# Find the links on the pagedumps = [a['href'] for a in soup_index.find_all('a') if a.has_attr('href')]dumps['../', '20180620/', '20180701/', '20180720/', '20180801/', '20180820/', '20180901/', '20180920/', 'latest/']
这段代码使用了BeautifulSoup库来解析HTML。由于HTML是网页的标准标识语言,因此就处理网络数据来说,这个库简直是无价瑰宝。
本项目使用的是2018年9月1日的dump(有些dump数据不全,请确保选择一个你所需的数据)。我们使用下列代码来找到dump里所有的文件。
dump_url = base_url + '20180901/'# Retrieve the htmldump_html = requests.get(dump_url).text# Convert to a soupsoup_dump = BeautifulSoup(dump_html, 'html.parser')# Find list elements with the class filesoup_dump.find_all('li', {'class': 'file'})[:3][
enwiki-20180901-pages-articles-multistream.xml.bz2 15.2 GB,
enwiki-20180901-pages-articles-multistream-index.txt.bz2 195.6 MB,
enwiki-20180901-pages-meta-history1.xml-p10p2101.7z 320.6 MB]
我们再一次使用BeautifulSoup来解析网络找寻文件。我们可以在https://dumps.wikimedia.org/enwiki/20180901/页面里手工下载文件,但这就不够效率了。网络数据如此庞杂,懂得如何解析HTML和在程序中与网页交互是非常有用的——学点网站检索知识,庞大的新数据源便触手可及。
考虑好下载什么
上述代码把dump里的所有文件都找出来了,你也就有了一些下载的选择:文章当前版本,文章页以及当前讨论列表,或者是文章所有历史修改版本和讨论列表。如果你选择最后一个,那就是万亿字节的数据量了!本项目只选用文章最新版本。
所有文章的当前版本能以单个文档的形式获得,但如果我们下载解析这个文档,就得非常费劲地一篇篇文章翻看,非常低效。更好的办法是,下载多个分区文档,每个文档内容是文章的一个章节。之后,我们可以通过并行化一次解析多个文档,显著提高效率。
“当我处理文档时,我更喜欢多个小文档而非一个大文档,这样我就可以并行化运行多个文档了。”
分区文档格式为bz2压缩的XML(可扩展标识语言),每个分区大小300~400MB,全部的压缩包大小15.4GB。无需解压,但如果你想解压,大小约58GB。这个大小对于人类的全部知识来说似乎并不太大。
维基百科压缩文件大小
下载文件
Keras 中的get_file语句在实际下载文件中非常好用。下面的代码可通过链接下载文件并保存到磁盘中:
from keras.utils import get_filesaved_file_path = get_file(file, url)
下载的文件保存在~/.keras/datasets/,也是Keras默认保存设置。一次性下载全部文件需2个多小时(你可以试试并行下载,但我试图同时进行多个下载任务时被限速了)
解析数据
我们首先得解压文件。但实际我们发现,想获取全部文章数据根本不需要这样。我们可以通过一次解压运行一行内容来迭代文档。当内存不够运行大容量数据时,在文件间迭代通常是唯一选择。我们可以使用bz2库对bz2压缩的文件迭代。
不过在测试过程中,我发现了一个更快捷(双倍快捷)的方法,用的是system utility bzcat以及Python模块的subprocess。以上揭示了一个重要的观点:解决问题往往有很多种办法,而找到最有效办法的唯一方式就是对我们的方案进行基准测试。这可以很简单地通过%%timeit Jupyter cell magic来对方案计时评价。
迭代解压文件的基本格式为:
data_path = '~/.keras/datasets/enwiki-20180901-pages-articles15.xml-p7744803p9244803.bz2# Iterate through compressed file one line at a timefor line in subprocess.Popen(['bzcat'], stdin = open(data_path), stdout = subprocess.PIPE).stdout: # process line
如果简单地读取XML数据,并附为一个列表,我们得到看起来像这样的东西:

维基百科文章的源XML
上面展示了一篇维基百科文章的XML文件。每个文件里面有成千上万篇文章,因此我们下载的文件里包含百万行这样的语句。如果我们真想把事情弄复杂,我们可以用正则表达式和字符串匹配跑一遍文档来找到每篇文章。这就极其低效了,我们可以采取一个更好的办法:使用解析XML和维基百科式文章的定制化工具。
解析方法
我们需要在两个层面上来解析文档:
1、从XML中提取文章标题和内容
2、从文章内容中提取相关信息
好在,Python对这两个都有不错的应对方法。
解析XML
解决第一个问题——定位文章,我们使用SAX(Simple API for XML) 语法解析器。BeautifulSoup语句也可以用来解析XML,但需要内存载入整个文档并且建立一个文档对象模型(DOM)。而SAX一次只运行XML里的一行字,完美符合我们的应用场景。
基本思路就是我们对XML文档进行搜索,在特定标签间提取相关信息。例如,给出下面这段XML语句:
Carroll F. Knicely'''Carroll F. Knicely''' (born c. 1929 in [[Staunton, Virginia]] - died November 2, 2006 in [[Glasgow, Kentucky]]) was [[Editing|editor]] and [[Publishing|publisher]] of the ''[[Glasgow Daily Times]]'' for nearly 20 years (and later, its owner) and served under three [[Governor of Kentucky|Kentucky Governors]] as commissioner and later Commerce Secretary.
'
我们想筛出在
和<text>这两标签间的内容(这个title就是维基百科文章标题,text就是文章内容)。SAX能直接让我们实现这样的功能——通过parser和ContentHandler这两个语句来控制信息如何通过解析器然后被处理。每次扫一行XML句子进解析器,Content Handler则帮我们提取相关的信息。</p>
<p style="text-indent: 2em;">
如果你不尝试做一下,可能理解起来有点难度,但是Content handler的思想是寻找开始标签和结束标签之间的内容,将找到的字符添加到缓存中。然后将缓存的内容保存到字典中,其中相应的标签作为对应的键。最后我们得到一个键是标签,值是标签中的内容的字典。下一步,我们会将这个字典传递给另一个函数,它将解析字典中的内容。</p>
<p style="text-indent: 2em;">
我们唯一需要编写的SAX的部分是Content Handler。全文如下:</p>
<p style="text-indent: 2em;">
在这段代码中,我们寻找标签为title和text的标签。每次解析器遇到其中一个时,它会将字符保存到缓存中,直到遇到对应的结束标签(</tag>)。然后它会保存缓存内容到字典中-- self._values。文章由<page>标签区分,如果Content Handler遇到一个代表结束的 </page> 标签,它将添加self._values 到文章列表(self._pages)中。如果感到疑惑了,实践观摩一下可能会有帮助。</p>
<p style="text-indent: 2em;">
下面的代码显示了如何通过XML文件查找文章。现在,我们只是将它们保存到handler._pages中,稍后我们将把文章发送到另一个函数中进行解析。</p>
<p style="text-indent: 2em;">
# Object for handling xmlhandler = WikiXmlHandler()# Parsing objectparser = xml.sax.make_parser()parser.setContentHandler(handler)# Iteratively process filefor line in subprocess.Popen(['bzcat'], stdin = open(data_path), stdout = subprocess.PIPE).stdout: parser.feed(line) # Stop when 3 articles have been found if len(handler._pages) > 2: break</p>
<p style="text-indent: 2em;">
如果我们观察 handler._pages,我们将看到一个列表,其中每个元素都是一个包含一篇文章的标题和内容的元组:</p>
<p style="text-indent: 2em;">
handler._pages[0][('Carroll Knicely', "'''Carroll F. Knicely''' (born c. 1929 in [[Staunton, Virginia]] - died November 2, 2006 in [[Glasgow, Kentucky]]) was [[Editing|editor]] and [[Publishing|publisher]] ...)]</p>
<p style="text-indent: 2em;">
此时,我们已经编写的代码可以成功地识别XML中的文章。现在我们完成了解析文件一半的任务,下一步是处理文章以查找特定页面和信息。再次,我们使用专为这项工作而创建的一个工具。</p>
<p style="text-indent: 2em;">
解析维基百科文章</p>
<p style="text-indent: 2em;">
维基百科运行在一个叫做MediaWiki的软件上,该软件用来构建wiki。这使文章遵循一种标准格式,这种格式可以轻易地用编程方式访问其中的信息。虽然一篇文章的文本看起来可能只是一个字符串,但由于格式的原因,它实际上编码了更多的信息。为了有效地获取这些信息,我们引进了强大的 mwparserfromhell, 一个为处理MediaWiki内容而构建的库。</p>
<p style="text-indent: 2em;">
如果我们将维基百科文章的文本传递给 mwparserfromhell,我们会得到一个Wikicode 对象,它含有许多对数据进行排序的方法。例如,以下代码从文章创建了一个wikicode对象,并检索文章中的 wikilinks()。这些链接指向维基百科的其他文章:</p>
<p style="text-indent: 2em;">
import mwparserfromhell# Create the wiki articlewiki = mwparserfromhell.parse(handler._pages[6][1])# Find the wikilinkswikilinks = [x.title for x in wiki.filter_wikilinks()]wikilinks[:5]['Provo, Utah', 'Wasatch Front', 'Megahertz', 'Contemporary hit radio', 'watt']</p>
<p style="text-indent: 2em;">
有许多有用的方法可以应用于wikicode,例如查找注释或搜索特定的关键字。如果您想获得文章文本的最终修订版本,可以调用:</p>
<p style="text-indent: 2em;">
wiki.strip_code().strip()'KENZ (94.9 FM, " Power 94.9 " ) is a top 40/CHR radio station broadcasting to Salt Lake City, Utah '</p>
<p style="text-indent: 2em;">
因为我的最终目标是找到所有关于书籍的文章,那么是否有一种方法可以使用解析器来识别某个类别中的文章呢?幸运的是,答案是肯定的——使用MediaWiki templates。</p>
<p style="text-indent: 2em;">
文章模板</p>
<p style="text-indent: 2em;">
模板(templates)是记录信息的标准方法。维基百科上有无数的模板,但与我们的目的最相关的是信息框( Infoboxes)。有些模板编码文章的摘要信息。例如,战争与和平的信息框是:</p>
<p align="center">
</p>
<p style="text-indent: 2em;">
维基百科上的每一类文章,如电影、书籍或广播电台,都有自己的信息框。在书籍的例子中,信息框模板被命名为Infobox book。同样,wiki对象有一个名为filter_templates()的方法,它允许我们从一篇文章中提取特定的模板。因此,如果我们想知道一篇文章是否是关于一本书的,我们可以通过book信息框去过滤。展示如下:</p>
<p style="text-indent: 2em;">
# Filter article for book templatewiki.filter_templates('Infobox book')</p>
<p style="text-indent: 2em;">
如果匹配成功,那我们就找到一本书了!要查找你感兴趣的文章类别的信息框模板,请参阅信息框列表。</p>
<p style="text-indent: 2em;">
如何将用于解析文章的mwparserfromhell 与我们编写的SAX解析器结合起来?我们修改了Content Handler中的endElement方法,将包含文章标题和文本的值的字典,发送到通过指定模板搜索文章文本的函数中。如果函数找到了我们想要的文章,它会从文章中提取信息,然后返回给handler。首先,我将展示更新后的endElement 。</p>
<p style="text-indent: 2em;">
def endElement(self, name): """Closing tag of element""" if name == self._current_tag: self._values[name] = ' '.join(self._buffer) if name == 'page': self._article_count += 1 # Send the page to the process article function book = process_article(**self._values, template = 'Infobox book') # If article is a book append to the list of books if book: self._books.append(book)</p>
<p style="text-indent: 2em;">
一旦解析器到达文章的末尾,我们将文章传递到函数 process_article,如下所示:</p>
<p style="text-indent: 2em;">
def process_article(title, text, timestamp, template = 'Infobox book'): """Process a wikipedia article looking for template""" # Create a parsing object wikicode = mwparserfromhell.parse(text) # Search through templates for the template matches = wikicode.filter_templates(matches = template) if len(matches) >= 1: # Extract information from infobox properties = {param.name.strip_code().strip(): param.value.strip_code().strip() for param in matches[0].params if param.value.strip_code().strip()} # Extract internal wikilinks</p>
<p style="text-indent: 2em;">
虽然我正在寻找有关书籍的文章,但是这个函数可以用来搜索维基百科上任何类别的文章。只需将模板替换为指定类别的模板(例如 Infobox language是用来寻找语言的),它只会返回符合条件的文章信息。</p>
<p style="text-indent: 2em;">
我们可以在一个文件上测试这个函数和新的ContentHandler 。</p>
<p style="text-indent: 2em;">
Searched through 427481 articles.Found 1426 books in 1055 seconds.</p>
<p style="text-indent: 2em;">
让我们看一下查找一本书的结果:</p>
<p style="text-indent: 2em;">
books[10]['War and Peace', {'name': 'War and Peace', 'author': 'Leo Tolstoy', 'language': 'Russian, with some French', 'country': 'Russia', 'genre': 'Novel (Historical novel)', 'publisher': 'The Russian Messenger (serial)', 'title_orig': 'Война и миръ', 'orig_lang_code': 'ru', 'translator': 'The first translation of War and Peace into English was by American Nathan Haskell Dole, in 1899', 'image': 'Tolstoy - War and Peace - first edition, 1869.jpg', 'caption': 'Front page of War and Peace, first edition, 1869 (Russian)', 'release_date': 'Serialised 1865–1867; book 1869', 'media_type': 'Print', 'pages': '1,225 (first published edition)'}, ['Leo Tolstoy', 'Novel', 'Historical novel', 'The Russian Messenger', 'Serial (publishing)', 'Category:1869 Russian novels', 'Category:Epic novels', 'Category:Novels set in 19th-century Russia', 'Category:Russian novels adapted into films', 'Category:Russian philosophical novels'], ['https://books.google.com/?id=c4HEAN-ti1MC', 'https://www.britannica.com/art/English-literature', 'https://books.google.com/books?id=xf7umXHGDPcC', 'https://books.google.com/?id=E5fotqsglPEC', 'https://books.google.com/?id=9sHebfZIXFAC'], '2018-08-29T02:37:35Z']</p>
<p style="text-indent: 2em;">
对于维基百科上的每一本书,我们把信息框中的信息整理为字典、书籍在维基百科中的wikilinks信息、书籍的外部链接和最新编辑的时间戳。(我把精力集中在这些信息上,为我的下一个项目建立一个图书推荐系统)。你可以修改process_article 函数和WikiXmlHandler类,以查找任何你需要的信息和文章!</p>
<p style="text-indent: 2em;">
如果你看一下只处理一个文件的时间,1055秒,然后乘以55,你会发现处理所有文件的时间超过了15个小时!当然,我们可以在一夜之间运行,但如果可以的话,我不想浪费额外的时间。这就引出了我们将在本项目中介绍的最后一种技术:使用多处理和多线程进行并行化。</p>
<p style="text-indent: 2em;">
并行操作</p>
<p style="text-indent: 2em;">
与其一次一个解析文件,不如同时处理其中的几个(这就是我们下载分区的原因)。我们可以使用并行化,通过多线程或多处理来实现。</p>
<p style="text-indent: 2em;">
多线程与多处理</p>
<p style="text-indent: 2em;">
多线程和多处理是同时在计算机或多台计算机上执行许多任务的方法。我们磁盘上有许多文件,每个文件都需要以相同的方式进行解析。一个简单的方法是一次解析一个文件,但这并没有充分利用我们的资源。因此,我们可以使用多线程或多处理同时解析多个文件,这将大大加快整个过程。</p>
<p style="text-indent: 2em;">
通常,多线程对于输入/输出绑定任务(例如读取文件或发出请求)更好(更快)。多处理对于cpu密集型任务更好(更快)。对于解析文章的过程,我不确定哪种方法是最优的,因此我再次用不同的参数对这两种方法进行了基准测试。</p>
<p style="text-indent: 2em;">
学习如何进行测试和寻找不同的方法来解决一个问题,你将会在数据科学或任何技术的职业生涯中走得更远。</p>
<p style="text-indent: 2em;">
相关报道:</p>
<p style="text-indent: 2em;">
https://towardsdatascience.com/wikipedia-data-science-working-with-the-worlds-largest-encyclopedia-c08efbac5f5c</p>
<p style="text-indent: 2em;">
【今日机器学习概念】</p>
<p style="text-indent: 2em;">
Have a Great Definition</p>
<p align="center">
</p>
<!-- copy 原来页面的推送 -->
<script type="application/ld+json">
{
"@context": "https://zhanzhang.baidu.com/contexts/cambrian.jsonld",
"@id": "https://m.elecfans.com/article/808775.html",
"title": "如何用Python编程下载和解析英文版维",
"images": [
"http://file.elecfans.com/web1/M00/6B/AB/pIYBAFveW72AXBryAAE54D9spRQ186.png"
],
"description": "从自然语言处理到监督式机器学习,维基百科助力了无数的数据科学项目。
维基百科的规模之大,可称为世上最大的百科全书,但也因此稍让数据工程师们感到头疼。当然,有合适的工具的话,数据量的规模就不是那么大的问题了。
本文将介绍“如何编程下载和解析英文版维基百科”。",
"pubDate": "2018-11-04T10:37:42"
}
</script>
<!-- end copy 原来页面的推送 -->
</div>
<!-- <a href="javascript:" target="_blank"></a> -->
<!-- <a href="https://www.elecfans.com/app/download.html" class="open_app_arc baidu_click_tongji2 inAppHide" target="_blank">打开APP阅读更多精彩内容</a> -->
<span class="open_app_arc baidu_click_tongji2 downAppBtn inAppHide">打开APP阅读更多精彩内容</span>
<div class="see_more_arc hide">
<div class="arrow_more show_more">
<i></i>
<i></i>
</div>
<button class="read_more">点击阅读全文</button>
</div>
</div>
</div>
<!--声明-无论是否原创都显示此声明-->
<div class="statement">
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
<a class="complaint handleJumpBy" href="/about/tousu.html" target="_self">举报投诉</a>
</div>
<!--评论-->
<div class="arc_comment comment">
</div>
<!--查看电子发烧友网-->
<div class="openx-hero inAppHide" style="text-align: center;">
<div class="advertWrap">
<a href="" target="_blank">
<img src="">
</a>
</div>
</div>
<div class="rela_article">
<div class="rela_article_title flex">
<ul class="tab_lis flex">
<li><span>相关推荐</span></li>
<li><a href="/tags/编程.html" target="_self" class="handleJumpBy advertTagId" data-id="5440">编程</a></li><li><a href="/tags/python.html" target="_self" class="handleJumpBy advertTagId" data-id="42127">python</a></li> </ul>
</div>
<ul class="rela_article_content">
<li
>
<a href="https://bbs.elecfans.com/jishu_71570_1_1.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">电子电路<b class='flag-m-1'>百科</b>全书<b class='flag-m-1'>下载</b></div>
<div class="time_and_hot flex">
<span>2009-09-25</span> <span>0</span> </div>
</a>
</li><li
>
<a href="https://bbs.elecfans.com/jishu_1100837_1_1.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct"><b class='flag-m-1'>维基百科</b>怎么上?Wikipedia打不开怎么办?</div>
<div class="time_and_hot flex">
<span>2016-12-08</span> <span>0</span> </div>
</a>
</li><li
>
<a href="https://bbs.elecfans.com/jishu_2217998_1_1.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">SPI通信协议的基础知识<b class='flag-m-1'>解析</b></div>
<div class="time_and_hot flex">
<span>2021-12-13</span> <span>0</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/soft/35/2006/20060314140.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">电子电路<b class='flag-m-1'>百科</b>全书</div>
<div class="time_and_hot flex">
<span>2006-03-14</span> <span>4687</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/soft/73/2010/2010031171019.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">pld基础入门<b class='flag-m-1'>百科</b>知识</div>
<div class="time_and_hot flex">
<span>2010-03-11</span> <span>652</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/news/wangluo/2009102198041.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">维基和<b class='flag-m-1'>百科</b>网站在中国的微妙局势</div>
<div class="time_and_hot flex">
<span>2009-10-21</span> <span>855</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/yuanqijian/dianchi/cailiao/2009102699801.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">石墨的<b class='flag-m-1'>百科</b>知识大全</div>
<div class="time_and_hot flex">
<span>2009-10-26</span> <span>4685</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/soft/32/2016/20160413414117.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">数据库-<b class='flag-m-1'>百</b>度<b class='flag-m-1'>百科</b></div>
<div class="time_and_hot flex">
<span>2016-05-04</span> <span>894</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/d/630663.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">生成<b class='flag-m-1'>英文</b><b class='flag-m-1'>维基百科</b>文章的方法可以概述为源文档的多文档摘要</div>
<div class="time_and_hot flex">
<span>2018-02-06</span> <span>6350</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/d/640841.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">流量一再降价 <b class='flag-m-1'>维基百科</b>关闭“Wikipedia Zero”计划</div>
<div class="time_and_hot flex">
<span>2018-08-05</span> <span>2482</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/blockchain/802218.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct"><b class='flag-m-1'>维基百科</b>联合创始人,计划将区块链技术运用到网络<b class='flag-m-1'>百科</b>全书中去</div>
<div class="time_and_hot flex">
<span>2018-10-23</span> <span>1344</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/blockchain/994965.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct"><b class='flag-m-1'>维基百科</b>联合创始人希望借助区块链技术打造一个去中心化的<b class='flag-m-1'>维基百科</b></div>
<div class="time_and_hot flex">
<span>2019-07-16</span> <span>1328</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/rengongzhineng/1254677.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">MIT推出<b class='flag-m-1'>维基百科</b>AI编辑系统</div>
<div class="time_and_hot flex">
<span>2020-07-21</span> <span>673</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/d/1381163.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">印度陷入政治两极化,<b class='flag-m-1'>维基百科</b>内容编辑也“乱了”</div>
<div class="time_and_hot flex">
<span>2020-11-15</span> <span>1147</span> </div>
</a>
</li><li
>
<a href="https://www.elecfans.com/soft/33/2021/202105061599334.html" target="_self" class="handleJumpBy">
<div class="rela_article_ct">STM8 CPU<b class='flag-m-1'>编程</b>手册<b class='flag-m-1'>英文版</b><b class='flag-m-1'>下载</b></div>
<div class="time_and_hot flex">
<span>2021-05-06</span> <span>940</span> </div>
</a>
</li> </ul>
</div>
<div class="go_elecfans ad-demo inAppHide"></div>
<!-- 全部评论 -->
<div class="all-comment comment">
<div class="all-comment-content">
<div class="all-com-close flex">
<p class="ph">全部<i>0</i>条评论</p>
<span class="close_com"></span>
<!-- <span class="edit_com">写评论</span> -->
</div>
<div class="all_words comment_content" id="all_words">
<div id="scroller"></div>
</div>
<div class="all_no_comment" class="hide">
<img src="https://staticm.elecfans.com/images/newdetail/all_no_bg.png" alt="">
<p>快来发表一下你的评论吧 !</p>
</div>
</div>
<div class="ft">
<input type="text" placeholder="发评论" maxlength="10000">
<button>发送</button>
</div>
</div>
<input type="hidden" id="cover_desc" value=" 没人否认,维基百科是现代最令人惊叹的人类发明之一。 几年前谁能想到,匿名贡献者们的义务工作竟创造出前所未有的巨大在线知识库?维基百科不仅是你写大学论文时最好的信息渠道,也是一个极其丰富的数据源。 从自然语言处理到监督式机器学习,维基百科助力了无数的数据科学项目。 维基百科的规模之大,可称为世上最大的百科全书,但也因此稍让数据工程师们感到头疼。当然,有合适的工具的话,数据量的规模就不是那么大的问题">
<input type="hidden" id="current_url" value="https://m.elecfans.com/article/808775.html">
<input type="hidden" id="title" value="如何用Python编程下载和解析英文版维基百科">
<input type="hidden" id="pc_domain" value="https://www.elecfans.com">
<input type="hidden" id="aid" value="808775">
<input type="hidden" id="pid" value="">
<!-- 文章作者id -->
<input type="hidden" id="column_uid" value="2788889">
<!-- 企业号文章id -->
<input type="hidden" id="evip_article_id" value="">
<!-- 是企业号文章 store_flag =15 -->
<input type="hidden" id="store_flag" value="0">
<input type="hidden" id="evip_type" value="0">
<!-- 是企业号文章 store_flag =15 -->
<input type="hidden" id="evip_id" value="0">
<!--打开APP底部悬浮按钮-->
<!-- <div class="open_app_btn">打开APP</div> -->
<footer class="art_footer flex">
<input type="text" placeholder="发评论" maxlength="10000" id="commentTxt">
<div class="flex">
<span class="ft_comment" data-com="发评论">
<i class="sups"></i>
</span>
<span class="ft_give_up ">
<!-- -->
</span>
<span class="ft_star ">
<!-- -->
</span>
<span class="ft_share btn-createCover"></span>
</div>
</footer>
<div class="login-reg-fixed inAppHide" data-uid="0">
<a href="/login.html" class="login-reg-btn">
登录/注册
</a> </div>
<!--二维码-->
<img src="" alt="" id="qrious" style="display: none;">
<!--老的底部 隐藏 -->
<div class="new-footer inAppHide">
<div class="flex-center"><a href="https://www.elecfans.com/app/download.html" target="_blank">下载APP</a></div>
<div class="flex-center">
<a href="/login.html" class="login-reg-btn">
登录注册
</a>
<span class="line">|</span><a href="https://m.elecfans.com/about/tousu.html">投诉反馈</a><span class="line">|</span><a href="https://author.baidu.com/home/1563378682824805?from=dusite_artdetailh5">电子发烧友网</a>
</div>
<div class="flex-center">© 2021 elecfans.com</div>
<div class="flex-center"><a href="https://beian.miit.gov.cn/">湘ICP备2023018690号</a></div>
<div><input type="hidden" value="0" name="arc_relate_vid"></div>
</div>
</div>
<!--微信分享图片地址-->
<input type="hidden" id="shareWxImg" value="http://file.elecfans.com/web1/M00/6B/AB/pIYBAFveW72AXBryAAE54D9spRQ186.png">
<!--微信分享图片地址-->
<script>
/**
* 判断是否微信浏览器
* @return {Boolean} [description]
*/
function is_weixin() {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
} else {
return false;
}
}
$(function () {
$(window).scroll(function (e) {
var window_w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var window_h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
if (document.body.scrollTop + document.documentElement.scrollTop > window_h * 2) {
$('.go_top').show();
}
else {
$('.go_top').hide();
}
});
$('.go_top').on('click', function () {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
return false;
});
// 添加广告链接的Google Analytics事件跟踪
$('a').on('click', function () {
var href = $(this).attr('href');
if (href) {
var bannerArr = href.match(/__bannerid=(\d+)__/);
var zoneidArr = href.match(/__zoneid=(\d+)__/);
if ((bannerArr instanceof Array) && bannerArr.length == 2) {
var bannerid = bannerArr[1];
var zoneid = zoneidArr[1];
ga('send', 'event', 'mElecfansAd', 'click', 'zoneid:' + zoneid + ',bannerid: ' + bannerid, 1);
gtag('event', 'mElecfansAd', { 'zoneid': zoneid, 'bannerid': 'bannerid', 'describe': 'click' });
}
}
});
// 微信浏览器底部显示关注微信
/* if (is_weixin()) {
$('#foot-fixed').hide();
$('#foot-fixed-wx').show();
}*/
$('#foot-img-wx-small').click(function () {
$('#body-wx-big img').toggle();
});
});
</script>
<!-- 是否完善资料代码 s -->
<div class="perfect_infomation_tip">
<span class="no_tip_day3">×</span>
<div class="perfect_infomation_tip_box go_perfect_btn">
<span class="tip_jifen_text">20</span>
<div>
<img class="tip_jifen" src="https://staticm.elecfans.com/images/tip_jifen.png">
</div>
<div>
完善资料,<br>赚取积分
</div>
</div>
</div>
<!-- 是否完善资料代码 e -->
<script src="https://staticm.elecfans.com/weixinPrize/js/layer_mobile/layer.js"></script>
<script src="https://staticm.elecfans.com/organizing/js/organizing.js?20230825" type="text/javascript" ></script>
<script src="https://staticm.elecfans.com/hqAdvert.js?v2" type="text/javascript" ></script>
<script src="https://staticm.elecfans.com/xgPlayer.js" type="text/javascript" ></script>
<script>
$(function(){
var scrollTimer
$(window).on("scroll",function(){
//滚动的时候悬浮缩回去 否则正常展示
$(".perfect_infomation_tip_box").css("right","0px")
clearTimeout(scrollTimer);
scrollTimer=setTimeout(function(){
$(".perfect_infomation_tip_box").css("right"," -70px");
},300)
})
// 用户下载附件判断登录
$("a[data-annex]").click(function(){
if($("#uid").attr("data-uid")== "0" || !$("#uid").attr("data-uid")){
window.location.href="/login.html"
}else{
var down_id= $(this).attr("data-annex");
var down_href= $('#'+down_id).val();
window.open(down_href);
}
return false
})
/* //判断当天是否弹出手机验证如果弹出这
if(typeof isVerification_new === "function"){
if(window.localStorage.getItem("m_verification")!==newDate_current()){
//弹出是否手机验证
//弹出是否手机验证
isVerification_new(function(){
//完成手机号验证 后判断是否完善资料
isPerfectInfo_phone($)
})
}
}*/
});
(function () {
//百度推广
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
} else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
//add sunjinliang 2021.1.11 copy 原来的统计
var user_uname = $('input[name="column-type-name"]').val();
//发烧友增加百度统计自定义变量统计单一用户数据访问量
var _hmt = _hmt || [];
if (_hmt && user_uname == '发烧友学院') {
_hmt.push(['_setCustomVar', 1, 'ChannelID', '发烧友学院', 3]);
}
var google_title = user_uname;
ga('send', { hitType: 'pageview', title: google_title, dimension0: 'Mobile' });
gtag('event', 'pageview', { 'title': google_title, 'dimension0': 'Mobile', 'describe': 'pageview' });
$(".baidu_click_tongji1").click(function(){
sendGA("头部")
})
$(".baidu_click_tongji2").click(function(){
sendGA("中部")
})
$(".baidu_click_tongji3").click(function(){
sendGA("尾部")
})
function sendGA(content){
//向百度发送数据
if(typeof(_hmt)!="undefined"){
//时间分类===_trackEvent 详情专题页面==zt_detail 点击事件==='click' 哪一个部分点击(content)==== 头部中部尾部
_hmt.push(['_trackEvent', "zt_detail", 'click', content]);
}
}
})();
</script>
<script src="https://staticm.elecfans.com/artilePartjs.js?v=20230803160700" type="text/javascript" ></script>
</body>
</html>