所以我正在用 Python 编写一个程序来从我最喜欢的网站中提取一部电影的评分。
评论示例链接:http: //timesofindia.indiatimes.com/entertainment/movie-reviews/hindi/Madras-Cafe-movie-review/movie-review/21975443.cms
目前,我正在使用 string.partition 命令来获取包含评级信息的部分源 html 代码。但是,这种方法非常缓慢。
获得电影评分的最快方法是什么?
这是我正在使用的代码:
#POST Request to TOI site, for review source
data_output = requests.post(review_link)
#Clean HTML code
soup = BeautifulSoup(data_output.text)
#Filter source data, via a dirty string partition method
#rating
texted = str(soup).partition(" stars,")
texted = texted[0].partition("Rating: ")
rating = texted[2]
#title
texted = texted[0].partition(" movie review")
texted = texted[0].partition("<title>")
title = texted[2]
#print stuff
print "Title:", title
print "Rating:", rating, "/ 5"
谢谢!