到目前为止,我的代码是:
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))
- jfs