【发布时间】:2013-12-18 03:14:43
【问题描述】:
到目前为止,我的代码是:
year = range(1958,2013)
randomYear = random.choice(year)
randomYear = str(randomYear)
page = range(1,5)
randomPage = random.choice(page)
randomPage = str(randomPage)
print(randomPage, randomYear)
url = 'http://www.billboard.com/artists/top-100/'+randomYear+'?page='+randomPage
url1 = urlopen(url)
htmlSource = url1.read()
url1.close()
soup = BeautifulSoup(htmlSource)
listm = soup.findAll('article', {'class': 'masonry-brick','style' : 'position; absolute; top; 0px; left: 0px;'})
for listm in soup.findAll('div',{'class': 'thumbnail'}):
for listm in soup.find('img alt')(''):
print(listm)
我想要做的是获取 img alt='' 文本。我想我说得对,但它什么也没显示。
【问题讨论】:
-
不相关:您可以使用字符串格式创建网址:
url = 'http://www.billboard.com/artists/top-100/{year}?page={page}'.format(year=random.randint(1958, 2013), page=random.randint(1, 5))注意:此代码与您的不同,包括两个端点。
标签: python beautifulsoup