码迷,mamicode.com
首页 > 其他好文 > 详细

11.6 项目: “I’m Feeling Lucky”百度 查找

时间:2017-04-27 23:11:24      阅读:597      评论:0      收藏:0      [点我收藏+]

标签:trie   asc   ogg   message   google   log   status   python3   range   

 1 #! python3
 2 # lucky.py - Opens several Google search results.
 3 import requests, sys, webbrowser,logging
 4 from bs4 import BeautifulSoup
 5 logging.disable(logging.CRITICAL)
 6 logging.basicConfig(level=logging.DEBUG, format=%(asctime)s - %(levelname)s - %(message)s)
 7 print(Baiduing...) # display text while downloading the Baidu page
 8 logging.debug(sys.argv[1:])
 9 res = requests.get(http://www.baidu.com/s?wd= + ‘‘.join(sys.argv[1:]))
10 res.encoding = utf-8
11 #logging.debug(res)^
12 res.raise_for_status()
13 # TODO: Retrieve top search result links.
14 soup = BeautifulSoup(res.text, "lxml")
15 #logging.debug(soup)
16 # TODO: Open a browser tab for each result.
17 linkElems = soup.select(div.result h3.t > a)
18 numOpen = min(8, len(linkElems))
19 for i in range(numOpen):
20   webbrowser.open(linkElems[i].get(href))

改成百度了,你懂的。

11.6 项目: “I’m Feeling Lucky”百度 查找

标签:trie   asc   ogg   message   google   log   status   python3   range   

原文地址:http://www.cnblogs.com/flying-wyf/p/6777332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!