0
我想要获得每个页面内的所有应用程序链接。但问题是每个类别内的总页面不一样。 我有这样的代码:如何迭代未知总页数中的链接?
import urllib
from bs4 import BeautifulSoup
url ='http://www.brothersoft.com/windows/mp3_audio/'
pageUrl = urllib.urlopen(url)
soup = BeautifulSoup(pageUrl)
for a in soup.select('div.coLeft.cate.mBottom dd a[href]'):
print 'http://www.brothersoft.com'+a['href'].encode('utf-8','repalce')
suburl = 'http://www.brothersoft.com'+a['href'].encode('utf-8','repalce')
for page in range(1,27+1):
content = urllib.urlopen(suburl+'{}.html'.format(page))
soup = BeautifulSoup(content)
for a in soup.select('div.freeText dl a[href]'):
print 'http://www.brothersoft.com'+a['href'].encode('utf-8','repalce')
但我只得到应用的链接,在每个类别27页。 如果其他类别没有27页或超过27页,该怎么办?
非常感谢你@ ton1c..This真的很有用! –
我刚刚发现第一页未打印。 –
发布您的代码和哪些页面未打印 – ton1c