2

Having a nightmare, so I have made a desktop scraper with Beautiful Soup and it works a treat, but trying to now but it into so kodi add on base code is being a right nightmare, I keep getting invalid syntax errors, and frankly I just don't know where to start on how to try and import it in.

Here is my desktop code:

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()
  • Here is my desktop code: – Nemzzy Builds Feb 06 '17 at 01:43
  • Sorry I don't understand, The above kodi won't work in Kodi so thequestionwas aimed at people who know kodi because they would know why the above code doesn't work, they would know what needs changing and what needs taken out – Nemzzy Builds Feb 06 '17 at 16:10

2 Answers2

1

You'll have to use python 2 and use the addon.xml to import your dependencies.

Razze
  • 4,124
  • 3
  • 16
  • 23
  • I have ported it for kodi 2.7 and got the dependancies, however it still doesn't work. I might have to re make a scraper using re.compile – Nemzzy Builds Feb 06 '17 at 21:46
0

Did you import bs4 module in addon xml? If not you have import script.module.bs4 in addon.xml as shown below:

<requires>
    <import addon="script.module.beautifulSoup4" version="3.3.0"/>
</requires>
Mika Sundland
  • 18,120
  • 16
  • 38
  • 50
Rachit kapadia
  • 705
  • 7
  • 18