我正在尝试提取此fandango页面上列出的电影名称。
names_tag = soup.findAll('a', {'class': 'dark showtimes-movie-title'})
这是名称隐藏的锚类。问题是,当我运行代码时,输出是:
<a class="dark showtimes-movie-title" href="http://www.fandango.com/godzilla3d_170083/movieoverview">Godzilla 3D</a>
当我想要在哥斯拉3D中。如何成功解析此数据?
#anchor element containing the names of each movie
names_tag = soup.findAll('a', {'class': 'dark showtimes-movie-title'})
names_tag = str(names_tag)
movie_name = names_tag.split(',')
for each_line in movie_name:
movie_names.append(each_line)
i = 0
while (i < len(movie_names)):
print 'The length of %s is %s' %(movie_names[i], movie_times[i])
i+=1
答案 0 :(得分:0)
使用text
属性:
names_tag = soup.findAll('a', {'class': 'dark showtimes-movie-title'})
names = [name_tag.text for name_tag in names_tag]