Alfred Workflow Python beautifulsoup crawler Browse NetEase News Headlines __python

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.