国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

基于Python開發chrome插件的方法分析

2020-02-15 22:13:52
字體:
來源:轉載
供稿:網友

本文實例講述了基于Python開發chrome插件的方法。分享給大家供大家參考,具體如下:

谷歌Chrome插件是使用HTML、JavaScript和CSS編寫的。如果你之前從來沒有寫過Chrome插件,我建議你讀一下這個。在這篇教程中,我們將教你如何使用Python代替JavaScript。

創建一個谷歌Chrome插件

首先,我們必須創建一個清單文件:manifest.json。

{ "manifest_version": 2, "name": "Python Chrome Plugin", "description": "This extension runs Python code.", "version": "1.0", "browser_action": {  "default_icon": "icon.png",  "default_popup": "popup.html" }, "permissions": [  "activeTab",  "https://ajax.googleapis.com/" ]}

然后創建一個名為popup.html的文件:

<!doctype html><!-- This page is shown when the extension button is clicked, because the "browser_action" field in manifest.json contains the "default_popup" key with value "popup.html". --><html> <head>  <title>Getting Started Extension's Popup</title>  <style>   body {    font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;    font-size: 100%;   }   #status {    /* avoid an excessively wide status text */    white-space: pre;    text-overflow: ellipsis;    overflow: hidden;    max-width: 400px;   }  </style>  <!--   - JavaScript and HTML must be in separate files: see our Content Security   - Policy documentation[1] for details and explanation.   -   - [1]: https://developer.chrome.com/extensions/contentSecurityPolicy   -->  <script src="popup.js"></script> </head> <body>  <div id="status"></div>  <img id="image-result" hidden> </body></html>

最后得到一個圖標,并保存為icon.png。打開chrome://extensions,點擊開發者模式。點擊“加載未打包擴展程序”,選擇文件夾,點擊OK。

為Chrome擴展程序添加Python

現在你擁有了最基本的權利,我們可以在代碼中添加Python。為了能在一個瀏覽器中運行Python,你有很多個選擇,包括Brython和emcascripten。我們決定使用Brython。我們將從一個服務器運行Brython腳本。改變popup.html的內容:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta charset="iso-8859-1"><style>body {  margin: 0 !important;  padding: 0 !important;  width: 800;}#frame {  overflow: hidden;  width:790;  height:324;}</style></head><body onLoad=""><iframe src=http://brython.info/console.html id="frame" seamless="seamless" scrolling="no"></iframe></body></html>

重啟下你的插件,你就會在你的谷歌Chrome瀏覽器中得到一個Python(Brython)解釋器。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳泉市| 江油市| 赣州市| 海门市| 阿瓦提县| 青铜峡市| 岑溪市| 巩留县| 东至县| 玛沁县| 遂昌县| 政和县| 恭城| 遂昌县| 清徐县| 且末县| 治多县| 松滋市| 辽源市| 高雄市| 轮台县| 邳州市| 江达县| 南康市| 浏阳市| 萨嘎县| 同江市| 揭东县| 庆城县| 时尚| 石家庄市| 驻马店市| 闻喜县| 广汉市| 呼伦贝尔市| 买车| 阿鲁科尔沁旗| 鄯善县| 荔波县| 桓仁| 泽普县|