开发者

BeautifulSoup always returns null when I use findAll

I'm trying to use BeautifulSoup to parse some webpages, and it always returns null whenever I use findAll even though I can access stuff like soup.title and whatnot just fine.

I'm trying to use this link to parse right now, and this is what I get when I try doing stuff with it:

>>> site = urllib2.urlopen('http://www.newegg.com/Product/ProductList.aspx?Submit=ENE&IsNodeId=1&Description=nvidia%20gtx%20560%20ti&bop=And&Order=PRICE&PageSize=20')                                                                                                                            
>>> soup = BeautifulSoup(site)                                                                                  
>>> soup.title                                                                                                                                   
<title>Newegg.com - nvidia gtx 560 ti</title>                                                                                                    
>>> soup.findAll('title')                                                                          开发者_开发百科                                              
Null                                                                                                                                             
>>>

Does anyone know why it's doing this? I'm using BeautifulSoup 2.1.1


You are using an old version of BeautifulSoup that doesn't have the findAll method. I believe the equivalent method for old versions was called fetch. The findAll method was added in BeautifulSoup version 3.0.0, when the method names were changed to be more consistent. From the documentation:

Previous versions of Beautiful Soup had methods like first, fetch, and fetchPrevious. These methods are sitll there, but they're deprecated, and may go away soon. The total effect of all those names was very confusing. The new names are named consistently: as mentioned above, if the method name is plural or refers to All, it returns multiple objects. Otherwise, it returns one object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜