firecat53 / urlscan

Mutt and terminal url selector (similar to urlview)
GNU General Public License v2.0
214 stars 38 forks source link

AttributeError: 'list' object has no attribute 'encode' #75

Closed desaismita closed 5 years ago

desaismita commented 5 years ago

from lxml import html import requests

class AppCrawler:

def __init__(self,starting_url,depth):
    self.starting_url = starting_url
    self.depth = depth
    self.apps = []

def crawl(self):
    self.get_app_from_link(self.starting_url)
    return

def get_app_from_link(self,Link):
    start_page = requests.get(Link)
    tree = html.fromstring(start_page.text)

    name = tree.xpath('//a[@class="link"]/text()')
    developer = tree.xpath('//div[@class="section__nav"]/h2/text()')[0]
    price = tree.xpath('//div[@class="l-row"]//*/h2/text()')[0]
    links = tree.xpath('//div[@class="section__nav"]//*/a[@class="link section__nav__see-all-link ember-view"]/@href')

    app = App(name,developer,price,links)

    self.apps.append(app)

    #print(links)
    return

class App: def init(self,name,developer,price,links): self.name = name self.developer = developer self.price = price self.links = links

def __str__(self):
    return('Name :' + self.name.encode('UTF-8') +
    '\r\nDeveloper :' + self.developer.encode('UTF-8') +
    '\r\nPrice :' + self.price.encode('UTF-8'))

crawler = AppCrawler("https://itunes.apple.com/us/app/candy-crush-saga/id553834731?mt=8", 0)

crawler.crawl()

for app in crawler.apps: print (app)

desaismita commented 5 years ago

Can anybody help me know why am I getting this error?

firecat53 commented 5 years ago

Not a urlscan issue.