从tvbythenumbers.zap2it.com访问收视率的python scraper
py-zap的Python项目详细描述
py_zap是一个python scraper,用于从tvbythenumbers.zap2it.com获取每日广播和有线电视收视率。
安装
使用pip安装:
>>> pip install py_zap
或者克隆此存储库并运行:
>>> python setup.py install
广播收视率
我们来取final broadcast ratings for October 27, 2016.
- 如果不包含日期参数,则默认为昨天的日期
>>> from py_zap import Broadcast >>> ratings = Broadcast('October 27, 2016')
- 现在我们可以查看图表条目:
>>> entry = ratings[0] # Gives the 1st entry >>> entry.show # Get the name of the show 'The Big Bang Theory' >>> entry.viewers # Get the number of viewers (in millions) 14.3 >>> entry.rating # Get the rating (percentage) 3.4
- 我们还可以print通过:
>>> print(ratings)
>>> Final Broadcast Ratings for Thursday, October 27 2016 |Show |Time |Network|Viewers|Rating |Share | +-------------------------------------------------------------------------+ |The Big Bang Theory | 8 p.m.| CBS| 14.3| 3.4| 13.0| |Grey’s Anatomy | 8 p.m.| ABC| 8.2| 2.2| 8.0| |Superstore | 8 p.m.| NBC| 4.2| 1.3| 5.0| |Rosewood | 8 p.m.| FOX| 3.4| 0.8| 3.0| |Legends of Tomorrow | 8 p.m.| The CW| 1.8| 0.6| 2.0| |The Great Indoors | 8:30 p.m.| CBS| 8.8| 1.9| 7.0| |The Good Place | 8:30 p.m.| NBC| 3.9| 1.2| 4.0| |Mom | 9 p.m.| CBS| 7.0| 1.5| 5.0| |Chicago Med | 9 p.m.| NBC| 7.1| 1.5| 5.0| |Notorious | 9 p.m.| ABC| 3.8| 0.8| 3.0| |Pitch | 9 p.m.| FOX| 2.9| 0.8| 3.0| |Supernatural | 9 p.m.| The CW| 1.7| 0.6| 2.0| |Life in Pieces | 9:30 p.m.| CBS| 6.0| 1.4| 5.0| |Pure Genius | 10 p.m.| CBS| 6.2| 1.0| 4.0| |The Blacklist | 10 p.m.| NBC| 5.5| 1.2| 4.0| |How to Get Away with Murder | 10 p.m.| ABC| 4.1| 1.2| 4.0|
默认情况下,将获取最终广播收视率。若要访问先前发布但不太准确的快速分级,请将“final”参数设置为false。如果没有可用的最终评级,它将重定向到快速访问评级。
>>> ratings = Broadcast('October 27, 2016', final=False)
电缆额定值
获取cable ratings for October 27, 2016:
>>> from py_zap import Cable >>> ratings = Cable('October 27, 2016')
其他可以做的事情
排序图结果
- 广播或有线电视的收视率可以根据show、net、time、rating或viewers 进行排序。
- 广播收视率只能在share上排序
>>> ratings = Cable('October 27, 2016').sort('viewers') # Sort cable ratings by viewers
>>> ratings = Broadcast('October 27, 2016').sort('share') # Sort broadcast ratings by share (broadcast only)
获取特定节目或网络
- 如果要获取多个列表,请传递列表
>>> ratings = Broadcast('October 27, 2016', show='Supernatural') # Fetch a specific show
>>> ratings = Broadcast('October 27, 2016', network=['CBS', 'NBC']) # Fetch a specific network
遍历多周
>>> next_week = ratings.get_next_week() # Get next week's date
>>> last_week = ratings.get_last_week() # Get last week's date
get network average(仅限广播)
>>> averages = ratings.get_averages() # Get the ratings/viewers averages for broadcast networks >>> averages['NBC'] {'rating': 1.3, 'viewers': 5.56, 'share': 5.0}
许可证
- 这个项目是在麻省理工学院的许可下进行的。
- 所有内容归论坛媒体公司所有。有关更多详细信息,请参见zap2it.com的Terms of Service。