python维基百科部分循环(代码片段)

author author     2022-12-27     457

关键词:

import wikipedia
import numpy as np

# you'll need to get the exact names of the titles of the pages beforehand
example_titles = 
['Algol (film)','Dr. Jekyll and Mr. Hyde (1920 Haydon film)',
 'Figures of the Night', 'The Invisible Ray (1920 serial)', 'The Man from Beyond',
 'Black Oxen','Aelita','The Hands of Orlac (1924 film)']

# create a list of all the names you think/know the section might be called
possibles = ['Plot','Synopsis','Plot synopsis','Plot summary', 
             'Story','Plotline','The Beginning','Summary',
            'Content','Premise']
# sometimes those names have 'Edit' latched onto the end due to 
# user error on Wikipedia. In that case, it will be 'PlotEdit'
# so it's easiest just to make another list that acccounts for that
possibles_edit = [i + 'Edit' for i in possibles]
#then merge those two lists together
all_possibles = possibles + possibles_edit

# now for the actual fetching!
for i in titles:
# load the page once and save it as a variable, otherwise it will request
# the page every time.
# always do a try, except when pulling from the API, in case it gets confused
# by the tttle.
    try:
        wik = wikipedia.WikipediaPage(i[0])
    except:
        wik = np.NaN

# a new try, except for the plot
    try:
        # for all possible titles in all_possibles list
        for j in all_possibles:
            # if that section does exist, i.e. it doesn't return 'None'
            if wik.section(j) != None:
                #then that's what the plot is! Otherwise try the next one!
                plot_ = wik.section(j).replace('\n','').replace("\'","")
    # if none of those work, or if the page didn't load from above, then plot
    # equals np.NaN
    except:
        plot= np.NaN

python从维基百科页面中截取所有表格标题(代码片段)

查看详情

python解析维基百科字符串中的文章链接(代码片段)

查看详情

python-bs4-仅使用表头+保存为字典从维基百科表中提取子表(代码片段)

我试图定义一个函数,它提取网站https://de.wikipedia.org/wiki/Stuttgart上的'Basisdaten'表的所有行,并返回一个字典,其键和值对应于表的每一行中的第一个和第二个单元格。'Basisdaten'表是更大表的一部分,如以下代码的结果所示:frombs... 查看详情

python脚本我曾经重命名所有f.r.i.e.n.d.s.通过从维基百科中获取名称来获取epsiodes(代码片段)

查看详情

text维基百科查看器(代码片段)

查看详情

php我觉得维基百科(代码片段)

查看详情

markdownfreecodecamp:构建维基百科查看器(代码片段)

查看详情

phpphpbot获取维基百科的定义(代码片段)

查看详情

markdownfreecodecamp:构建维基百科查看器(代码片段)

查看详情

python抓取维基百科,从随机文章开始。点击每篇文章中的第一个链接,看看我们结束的地方!扰流警报:可能在t(代码片段)

查看详情

ruby简单的ruby脚本来获取维基百科今天的精选文章(代码片段)

查看详情

ruby快速刮刀获取维基百科的第一段以获取主题列表(代码片段)

查看详情

spark实战之:分析维基百科网站统计数据(java版)(代码片段)

...访问我的GitHub在《寻找海量数据集用于大数据开发实战(维基百科网站统计数据)》一文中,我们获取到维基百科网站的网页点击统计数据,也介绍了数据的格式和内容,今天就用这些数据来练习基本的spark开发,<fontcolor="red... 查看详情

寻找海量数据集用于大数据开发实战(维基百科网站统计数据)(代码片段)

...一个海量数据集的下载方法,以及数据内容的简介;关于维基百科网站统计数据数据的下载页面地址:https://dumps.wikimedia.org/other/pagecounts-raw今天要下载的数据集就是维基百科的统 查看详情

转帖维基百科中的各国海军现役舰艇②:美国海军(代码片段)

维基百科中的各国海军现役舰艇②:美国海军 https://zhuanlan.zhihu.com/p/72327890美国总吨位420万吨中国过去十年下水140万吨。。 TheUnitedStatesNavyhasapproximately 490 shipsinboth activeservice and thereservefleet,withapproximately... 查看详情

字节序:大端和小端(bigendianandlittleendian)(转自维基百科)(代码片段)

简介[编辑]在几乎所有的机器上,多字节对象都被存储为连续的字节序列。例如在C语言中,一个类型为int的变量x地址为0x100,那么其对应地址表达式&x的值为0x100。且x的四个字节将被存储在存储器的0x100,0x101,0x102,0x103位置。[1]... 查看详情

如何使用库来获取维基百科页面?(代码片段)

我一直试图弄清楚mwapi库(MediaWikiAPI)的文档,我无法弄清楚如何根据搜索查询或关键字简单地请求页面。我知道我应该使用get(),但用关键字填充参数会产生错误。有谁知道这是如何工作来查找像“地球风和火”这样的东西?... 查看详情

维基百科

1.什么是GNU/Linux?在GNU/Linux系统中,Linux就是内核组件。而该系统的其余部分主要是由GNU工程编写和提供的程序组成。因为单独的Linux内核并不能成为一个可以正常工作的操作系统,所以我们更倾向使用 “GNU/Linux” ... 查看详情