deal_way = list(soup.select('p.biaoqian_li').stripped_strings)
#
deal_ways = soup.select('p.biaoqian_li')
for deal_way in deal_ways:
x = list(deal_way.stripped_strings)
上面两个代码不是表示同样的意思吗?
(1)为什么上面报错:AttributeError: 'list' object has no attribute 'stripped_strings'
(2)下面的可以运行
Yes
soup.select()
返回的是什么不是很清楚,但是看你下面的代码soup.select('p.biaoqian_li')
returns a collection. Only the items in the collection have the stripped_strings attribute, not the collection.The two pieces of code are different
Obviously the code below uses one more
for
than the above codeYou can print
soup.select('p.biaoqian_li')
andsoup.select('p.biaoqian_li')
与for
中的deal_way
indeal_way
Compare the differences
I’m really sorry, I didn’t make it clear at the beginning
It’s because I made a mistake in writing the code, so I keep reporting errors. It’s written as:
Thank you everyone