1
771456556 OP 或者可不可以把 find_all 的结果全部转换成 string ,
|
2
b1eberg0n 2016-10-25 01:05:56 +08:00
a = soup.findall('a')
b = a[0].findall('b') |
3
Arthur2e5 2016-10-25 01:47:59 +08:00
改写一下 @b1eberg0n ,来个范围攻击的……
a_b = [a.findall('b') for a in soup.findall('a')] a_b_flat = [result for a in soup.findall('a') for result in a.findall('b')] |
4
771456556 OP |
6
orange88 2016-10-25 07:34:02 +08:00 via Android
li 是 none ,上一个没找到?
|
7
771456556 OP @orange88 li[0]能打印出来,我用 print 打印出了,但是加上 b=li 那句话就打印失败了,很费解
|
8
orange88 2016-10-25 07:41:42 +08:00 via Android
li[0].findall
|
10
whwq2012 2016-10-25 08:12:31 +08:00 via Android
find_all 返回的结果是个 list ,要其中的结果得把它迭代一遍才行,最好再加个异常处理,防止出现你这样的情况
|
11
practicer 2016-10-25 09:08:16 +08:00
get_all_secondary_elements(bs)
try: top_elements = bs.find_all(...) for top_element in top_elements: secondary_elements = top_element.find_all(...) if secondary_elements is not None: yield secondary_elements except (AttributeError, TypeError): yield secondary_elements = list(get_all_secondary_elements) |
12
wyntergreg 2016-10-25 10:10:53 +08:00
转成 tag 再 findall
|
13
b1eberg0n 2016-10-25 10:24:54 +08:00
|