Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python:错误:[<;\uuuuu main\uuuu.class实例在0x>;]_Python_Function_Class_Instance - Fatal编程技术网

python:错误:[<;\uuuuu main\uuuu.class实例在0x>;]

python:错误:[<;\uuuuu main\uuuu.class实例在0x>;],python,function,class,instance,Python,Function,Class,Instance,我想在苹果商店的应用程序网站上拼凑出应用程序的名称,然后在终端上打印出来 这是我的密码: 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

我想在苹果商店的应用程序网站上拼凑出应用程序的名称,然后在终端上打印出来

这是我的密码:

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)

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

        name =  tree.xpath('//h1[@itemprop="name"]/text()')[0]
        app = App(name)
        self.apps.append(app)

class App:
    def __init__(self,name):
        self.name=name
    def __str__(self):
        return ("Name:" + self.name)

crawler = AppCrawler('https://itunes.apple.com/us/app/candy-crush-saga/id553834731',0)
crawler.crawl()
################ print the list ##################################
print crawler.apps
################ print the element in the list ###################
for app in crawler.apps:
    print app
以下是我在终点站得到的信息:

[<__main__.App instance at 0x029C3EE0>]
AppName:Candy Crush Saga
[]
AppName:Candy Crush Saga
我的问题是:

为什么列表打印是[] 并使用“for in”循环打印列表中的元素是否完全正确???

尝试:

for app in crawler.apps:
    print str(app)
或实施


\uuuuuu repr\uuuuu
而不是列表中的
\uuuuu str\uuuuuu

,调用的是
\uuuuuu repr\uuuu
方法,而不是
\uuuuuu str\uuu