Preface
The author leisure will be in NetEase news Browsing News, before a Alfred workflow based on the introduction of Python case, the main logic is the input content directly after the item content, the operation is more monotonous. So by further learning Alfred Workflow, you can activate the next action by selecting the parameters in the item to pass in. On this basis, I use Python's beautifulsoup Reptile Library to write a workflow to browse NetEase news headlines.
effect
Step to create an empty workflow program, add a script Filter
Add an open URL Action
Code Analysis
#-*-Coding:utf-8-*-
#导入需要使用到的模块
import
urllib2 from
Workflow Import workflow
from BS4 Import BeautifulSoup
def main (WF):
#加载url读取到的页面元素
html = urllib2.urlopen (url= "http://news.163.com/"). Read ()
#转换为BeautifulSoup对象
bsobj = beautifulsoup (HTML)
#获取头条新闻所在的标签内容
title_big_2_set = Bsobj.find ("div", {"Class": "Mod_top_news2"}). Find_all ("a")
#遍历头条新闻内容 for
i in Title_big_2_set:
# Title:item title, current headline news text content; ARG: The parameter passed, the current link to the headline news content; valid: whether to activate the next action, which is currently true
Wf.add_item (title=i.get_text (), arg=i.attrs[' href '],valid=true)
wf.send_feedback ()
if __name__ = = u "__main__":
wf = Workflow ()
Sys.exit (Wf.run (main))
Connect the script filter with the open URL
End before browsing news: Mobile Mouse--Open browser (click once)--open NetEase News (mouse click two times)--Browse the News (mobile Mouse)--Open News content (mouse click two times). Browse News Now: shortcut keys to open Alfred (I'm tapping command two times)--type "news"--Browse News--Enter the news content.
Browsing through Alfred has made it much easier and quicker than before.