.*
是一个贪心匹配,你可能应该使用.*?
非贪心版本。
这是您尝试匹配的记录之一的示例
'<div class="product"><div class="productImage"><a href="../SearchTools/item-details.asp?EdpNo=4903661&Sku=T71-156409" class="itemImage" title="Lenovo Z580 15.6" Core i7 500GB HDD Notebook PC"><img src="http://images.highspeedbackbone.net/skuimages/medium/T71-156409_chiclet01xx_er.jpg" alt="It features a powerful 3rd generation Intel Core i7-3520M and a 4GB DDR3 RAM which deliver you a powerful computing performance." onerror="this.src=\'http://images.highspeedbackbone.net/SearchTools/no_image-sm.jpg\'" border="0" /></a></div><div class="productInfo"><h3 class="itemName"><a href="../SearchTools/item-details.asp?EdpNo=4903661&Sku=T71-156409" title="Lenovo Z580 15.6" Core i7 500GB HDD Notebook PC">Lenovo Z580 15.6" Core i7 500GB HDD Notebook PC</a></h3></div>'
看起来您也需要删除周围的.*
空格
>>> response=urllib2.urlopen('http://www.tigerdirect.com/applications/Category/guidedSearch.asp?CatId=17&cm_sp=Masthead-_-Computers-_-Spot%2002')
>>> stuff=response.read()
>>> laptops= re.findall(r'<div class="product">.*?</div>',stuff)
>>> len(laptops)
16
解析 HTML 有更好的方法,例如BeautifulSoup