【问题标题】:Beautiful Soup Kodi scraper美丽的汤科迪刮刀
【发布时间】:2017-02-06 01:42:10
【问题描述】:

做了一个噩梦,所以我用 Beautiful Soup 做了一个桌面刮刀,它很有效,但现在尝试将它添加到基础代码上的 kodi 是一个正确的噩梦,我不断收到无效的语法错误,并且坦率地说,我只是不知道如何尝试导入它。

这是我的桌面代码:

url = input("Enter the direct url for the Tv Show you wish to pull: ")
tvname = input("Enter the name of the TV Show: ")
ui = tvname + '.xml' 
response = opener.open(url)
page = response.read()
soup = BeautifulSoup(page, "html.parser")
tv_urls = []
newfile = open(ui, "w")

def get_soup(url):
	response = opener.open(url)
	page = response.read()
	soup = BeautifulSoup(page, "html.parser")
	return soup

soup = get_soup(url)
seasonepisode =(soup.find_all('td', {'width' : '100%'})[-2].string)
cols=soup.find_all('td', { 'width' : '100%', 'class' : 'entry'})
all_links = [col.find('a').get('href') for col in cols]
tv_urls.extend(all_links)

for url in tv_urls:
	soup = get_soup(url)
	title = soup.title.string
	thumbnail=soup.select_one('td.summary img[src]')['src']
	cols=soup.find_all('td', { 'width' : '100%', 'class' : 'entry'})
	all_links = [col.find('a').get('href') for col in cols][1:]
	string='<item>\n<title>[COLOR lime]' + title + '[/COLOR]</title>\n'
	for  link in all_links:
		string = string + '<link>' + link + '</link>\n'
	string=string+'<thumbnail>' + thumbnail + '</thumbnail>\n<fanart> </fanart>\n</item>\n\n'
	newfile.write(string)
	print((title + ' Tv links scraped'))

print('Done Master Nemzzy')
newfile.close()

【问题讨论】:

  • 这是我的桌面代码:
  • 对不起,我不明白,上面的 kodi 不能在 Kodi 中工作,所以这个问题是针对那些了解 kodi 的人,因为他们会知道为什么上面的代码不起作用,他们会知道需要什么变化和需要采取的措施

标签: python-3.x web web-scraping kodi


【解决方案1】:

您必须使用 python 2 并使用 addon.xml 来导入您的依赖项。

【讨论】:

  • 我已将它移植到 kodi 2.7 并获得了依赖项,但它仍然无法正常工作。我可能不得不使用 re.compile 重新制作刮板
【解决方案2】:

您是否在插件 xml 中导入 bs4 模块?如果没有,则在 addon.xml 中导入 script.module.bs4,如下所示:

<requires>
    <import addon="script.module.beautifulSoup4" version="3.3.0"/>
</requires>

【讨论】:

    猜你喜欢
    • 2021-01-15
    • 2020-12-13
    • 2019-03-13
    • 2014-05-28
    • 2020-09-28
    • 1970-01-01
    • 2021-11-19
    • 2018-12-29
    相关资源
    最近更新 更多