小编Ale*_*lex的帖子

如何打印我认为的对象?

test = ["a","b","c","d","e"]

def xuniqueCombinations(items, n):
    if n==0: yield []
    else:
        for i in xrange(len(items)-n+1):
            for cc in xuniqueCombinations(items[i+1:],n-1):
                yield [items[i]]+cc

x = xuniqueCombinations(test, 3)
print x
Run Code Online (Sandbox Code Playgroud)

输出

"generator object xuniqueCombinations at 0x020EBFA8"
Run Code Online (Sandbox Code Playgroud)

我希望看到它找到的所有组合.我怎样才能做到这一点?

python generator

11
推荐指数
1
解决办法
9511
查看次数

为什么我在Python中使用BeautifulSoup得到"'ResultSet'没有属性'findAll'"?

所以我正在慢慢地学习Python,并且我正在尝试创建一个简单的函数,它将从在线游戏的高分页面中提取数据.这是我重写为一个函数的其他人的代码(这可能是问题),但是我收到了这个错误.这是代码:

>>> from urllib2 import urlopen
>>> from BeautifulSoup import BeautifulSoup
>>> def create(el):
    source = urlopen(el).read()
    soup = BeautifulSoup(source)
    get_table = soup.find('table', {'id':'mini_player'})
    get_rows = get_table.findAll('tr')
    text = ''.join(get_rows.findAll(text=True))
    data = text.strip()
    return data

>>> create('http://hiscore.runescape.com/hiscorepersonal.ws?user1=bigdrizzle13')

Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    create('http://hiscore.runescape.com/hiscorepersonal.ws?user1=bigdrizzle13')
  File "<pyshell#17>", line 6, in create
    text = ''.join(get_rows.findAll(text=True))
AttributeError: 'ResultSet' object has no attribute 'findAll'
Run Code Online (Sandbox Code Playgroud)

提前致谢.

python urllib2 beautifulsoup

8
推荐指数
1
解决办法
2万
查看次数

什么是网络爬虫的理想程序语言?

我需要构建一个内容收集程序,它只需读取指定网页上的数字,然后保存该数据以供日后分析.我不需要它来搜索链接或相关数据,只需从每天都有不断变化的内容的网站收集所有数据.

我的编程经验很少,我希望这对学习有好处.速度不是一个大问题,我估计爬虫最多每天需要加载4000页.

谢谢.

编辑:如果我收集数据的网站受到爬虫的保护,有没有办法提前测试?

web-crawler

6
推荐指数
2
解决办法
1万
查看次数

如何使用urllib2从Python中打开的URL中提取特定数据?

我是Python的新手,正在玩一个非常基本的网络爬虫.例如,我做了一个简单的功能来加载显示在线游戏的高分的页面.所以我能够获得html页面的源代码,但我需要从该页面中绘制特定的数字.例如,网页如下所示:

http://hiscore.runescape.com/hiscorepersonal.ws?user1=bigdrizzle13

其中'bigdrizzle13'是链接的独特部分.需要绘制并返回该页面上的数字.从本质上讲,我想构建一个程序,我所要做的就是输入'bigdrizzle13'并输出这些数字.

python urllib2

3
推荐指数
1
解决办法
3513
查看次数

标签 统计

python ×3

urllib2 ×2

beautifulsoup ×1

generator ×1

web-crawler ×1