我试图在https://dev.wikidebates.org/wiki/Wikidébats:Accueil中创建一个页面,它类似于ti wikipedia,所以Pywikibot应该以同样的方式工作。我想用Pywikibot创建一个页面。我在Pywikibot https://www.mediawiki.org/wiki/Manual:Pywikibot/Scripts中检查了选项脚本。脚本pagefromfile.py负责它。但是,我在代码中没有看到我应该在wiki的新页面上写链接。还在类page文件返回页面中进行互操作。我怎样才能确认这一页是建好的?
我现在尝试的代码如下。一切正常,除了最后一行。(没有创建页面)
site = pywikibot.Site('dev', 'wikidebates') # The site we want to run our bot on
page = pywikibot.Page(site, "Faut-il légaliser le cannabis ?")
text = page.get() #get the code of the page
wb = open("pages1.txt", "w", encoding="utf-8")
wb.write(str(txt)) #write text to the file, in order to download it then to the wiki
wb.close()
main_page('-file:pages1.txt') #use main function from scrip pagefromfile.py - I renamed it发布于 2022-07-07 10:10:21
你还没有提供任何进一步的信息。可能还有来自pagefromfile.py脚本的更多消息。如果您从wiki下载文本,则必须将开始标记和结束标记包含到文本中,或者必须使用-textonly选项。我还建议使用-title选项。
请参阅文档:https://doc.wikimedia.org/pywikibot/stable/scripts/general.html#module-scripts.pagefromfile
from scripts.pagefromfile import main # or main_page in your modified case
site = pywikibot.Site('wikidebates:dev') # you may use te site name for the constructor function
page = pywikibot.Page(site, 'Faut-il légaliser le cannabis ?')
text = page.text
with open("pages1.txt", "w", encoding="utf-8") as wp: # also closes the file
wb.write(text)
main('-file:pages1.txt', '-textonly', '-title:"The new title"')若要指定目标站点,请在主函数中添加一个-site选项(如果它不是默认站点)。为了模拟的目的,您可以使用-simulate选项:
main('-file:pages1.txt', '-textonly', '-title:"The new title"', '-simulate', '-site:wikidebates:dev')注释:给main函数的所有参数都必须用逗号分隔。除了这样做之外,不能将所有参数作为长字符串来表示:
main(*'-file:pages1.txt -textonly -title:The_new_title'.split())https://stackoverflow.com/questions/72752800
复制相似问题