国产探花免费观看_亚洲丰满少妇自慰呻吟_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)解釋器。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 神池县| 莆田市| 丹寨县| 宣威市| 富锦市| 彰化市| 定州市| 枞阳县| 赤壁市| 富民县| 陇南市| 婺源县| 建德市| 林州市| 共和县| 元朗区| 延边| 金溪县| 怀远县| 南木林县| 昌吉市| 图木舒克市| 鹰潭市| 杭州市| 崇阳县| 江油市| 高青县| 元氏县| 陇川县| 常州市| 云霄县| 犍为县| 怀柔区| 鄂托克前旗| 怀化市| 乐山市| 巴楚县| 张家港市| 会昌县| 吴旗县| 徐水县|