久久精品国产亚洲高清|精品日韩中文乱码在线|亚洲va中文字幕无码久|伊人久久综合狼伊人久久|亚洲不卡av不卡一区二区|精品久久久久久久蜜臀AV|国产精品19久久久久久不卡|国产男女猛烈视频在线观看麻豆

    1. <style id="76ofp"></style>

      <style id="76ofp"></style>
      <rt id="76ofp"></rt>
      <form id="76ofp"><optgroup id="76ofp"></optgroup></form>
      1. 千鋒教育-做有情懷、有良心、有品質的職業(yè)教育機構

        手機站
        千鋒教育

        千鋒學習站 | 隨時隨地免費學

        千鋒教育

        掃一掃進入千鋒手機站

        領取全套視頻
        千鋒教育

        關注千鋒學習站小程序
        隨時隨地免費學習課程

        當前位置:首頁  >  技術干貨  > 13個用于日常編程的高級Python腳本

        13個用于日常編程的高級Python腳本

        來源:千鋒教育
        發(fā)布人:qyf
        時間: 2023-02-23 16:56:00 1677142560

          每天我們都會面臨許多需要高級編碼的編程挑戰(zhàn)。你不能用簡單的 Python 基本語法來解決這些問題。在本文中,我將分享 13 個高級 Python 腳本,它們可以成為你項目中的便捷工具。如果你目前還用不到這些腳本,你可以先添加收藏,以備留用。

          好了,我們現(xiàn)在開始吧。

          1.使用 Python 進行速度測試

          這個高級腳本幫助你使用 Python 測試你的 Internet 速度。只需安裝速度測試模塊并運行以下代碼。

          # pip install pyspeedtest

          # pip install speedtest

          # pip install speedtest-cli

          #method 1

          import speedtest

          speedTest = speedtest.Speedtest()

          print(speedTest.get_best_server())

          #Check download speed

          print(speedTest.download())

          #Check upload speed

          print(speedTest.upload())

          # Method 2

          import pyspeedtest

          st = pyspeedtest.SpeedTest()

          st.ping()

          st.download()

          st.upload()

          2.在谷歌上搜索

          你可以從 Google 搜索引擎中提取重定向 URL,安裝以下提及模塊并遵循代碼。

          # pip install google

          from googlesearch import search

          query = "Medium.com"

          for url in search(query):

          print(url)

          3.制作網(wǎng)絡機器人

          該腳本將幫助你使用 Python 自動化網(wǎng)站。你可以構建一個可控制任何網(wǎng)站的網(wǎng)絡機器人。查看下面的代碼,這個腳本在網(wǎng)絡抓取和網(wǎng)絡自動化中很方便。

          # pip install selenium

          import time

          from selenium import webdriver

          from selenium.webdriver.common.keys

          import Keysbot = webdriver.Chrome("chromedriver.exe")

          bot.get('http://www.google.com')

          search = bot.find_element_by_name('q')

          search.send_keys("@codedev101")

          search.send_keys(Keys.RETURN)

          time.sleep(5)

          bot.quit()

          4.獲取歌曲歌詞

          這個高級腳本將向你展示如何從任何歌曲中獲取歌詞。首先,你必須從 Lyricsgenius 網(wǎng)站獲得免費的 API 密鑰,然后,你必須遵循以下代碼。

          # pip install lyricsgenius

          import lyricsgenius

          api_key = "xxxxxxxxxxxxxxxxxxxxx"

          genius = lyricsgenius.Genius(api_key)

          artist = genius.search_artist("Pop Smoke",

          max_songs=5,sort="title")

          song = artist.song("100k On a Coupe")

          print(song.lyrics)

          5.獲取照片的Exif數(shù)據(jù)

          使用 Python Pillow 模塊獲取任何照片的 Exif 數(shù)據(jù)。查看下面提到的代碼。我提供了兩種方法來提取照片的 Exif 數(shù)據(jù)。

          # Get Exif of Photo

          # Method 1

          # pip install pillow

          import PIL.Image

          import PIL.ExifTags

          img = PIL.Image.open("Img.jpg")

          exif_data =

          {

          PIL.ExifTags.TAGS[i]: j

          for i, j in img._getexif().items()

          if i in PIL.ExifTags.TAGS

          }

          print(exif_data)

          # Method 2

          # pip install ExifRead

          import exifread

          filename = open(path_name, 'rb')

          tags = exifread.process_file(filename)

          print(tags)

          6.提取圖像中的 OCR 文本

          OCR 是一種從數(shù)字和掃描文檔中識別文本的方法。許多開發(fā)人員使用它來讀取手寫數(shù)據(jù),下面的 Python 代碼可以將掃描的圖像轉換為 OCR 文本格式。

          注意:你必須從 Github 下載 tesseract.exe

          # pip install pytesseract

          import pytesseract

          from PIL import Image

          pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

          t=Image.open("img.png")

          text = pytesseract.image_to_string(t, config='')

          print(text)

          7.將照片轉換為Cartonize

          這個簡單的高級腳本會將你的照片轉換為 Cartonize 格式。查看下面的示例代碼并嘗試一下。

          # pip install opencv-python

          import cv2

          img = cv2.imread('img.jpg')

          grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

          grayimg = cv2.medianBlur(grayimg, 5)

          edges = cv2.Laplacian(grayimg , cv2.CV_8U, ksize=5)

          r,mask =cv2.threshold(edges,100,255,cv2.THRESH_BINARY_INV)

          img2 = cv2.bitwise_and(img, img, mask=mask)

          img2 = cv2.medianBlur(img2, 5)

          cv2.imwrite("cartooned.jpg", mask)

          8.清空回收站

          這個簡單的腳本可以讓你用 Python 清空你的回收站,查看下面的代碼以了解如何操作。

          # pip install winshell

          import winshell

          try:

          winshell.recycle_bin().empty(confirm=False, /show_progress=False, sound=True)

          print("Recycle bin is emptied Now")

          except:

          print("Recycle bin already empty")

          9.Python 圖像增強

          使用 Python Pillow 庫增強你的照片以使其看起來更好。在下面的代碼中,我實現(xiàn)了四種方法來增強任何照片。

          # pip install pillow

          from PIL import Image,ImageFilter

          from PIL import ImageEnhance

          im = Image.open('img.jpg')

          # Choose your filter

          # add Hastag at start if you don't want to any filter below

          en = ImageEnhance.Color(im)

          en = ImageEnhance.Contrast(im)

          en = ImageEnhance.Brightness(im)

          en = ImageEnhance.Sharpness(im)# result

          en.enhance(1.5).show("enhanced")

          10.獲取 Window 版本

          這個簡單的腳本將幫助你獲得當前使用的完整窗口版本。

          # Window Versionimport wmi

          data = wmi.WMI()

          for os_name in data.Win32_OperatingSystem():

          print(os_name.Caption)

          # Microsoft Windows 11 Home

          11.將 PDF 轉換為圖像

          使用以下代碼將所有 Pdf 頁轉換為圖像。

          # PDF to Images

          import fitz

          pdf = 'sample_pdf.pdf'

          doc = fitz.open(pdf)

          for page in doc:

          pix = page.getPixmap(alpha=False)

          pix.writePNG('page-%i.png' % page.number)

          12.轉換:十六進制到 RGB

          該腳本將簡單地將 Hex 轉換為 RGB。查看下面的示例代碼。

          # Conversion: Hex to RGB

          def Hex_to_Rgb(hex):

          h = hex.lstrip('#')

          return tuple(int(h[i:i+2], 16) for i in (0, 2, 4))

          print(Hex_to_Rgb('#c96d9d')) # (201, 109, 157)

          print(Hex_to_Rgb('#fa0515')) # (250, 5, 21)

          13.網(wǎng)站狀態(tài)

          你可以使用 Python 檢查網(wǎng)站是否正常運行。檢查以下代碼,顯示200 ,表示網(wǎng)站已啟動,如果顯示為 404 ,則表示網(wǎng)站已關閉。

          # pip install requests

          #method 1

          import urllib.request

          from urllib.request import Request, urlopenreq = Request('https://medium.com/@pythonians', headers={'User-Agent': 'Mozilla/5.0'})

          webpage = urlopen(req).getcode()

          print(webpage) # 200

          # method 2

          import requests

          r = requests.get("https://medi

        tags:
        聲明:本站稿件版權均屬千鋒教育所有,未經(jīng)許可不得擅自轉載。
        10年以上業(yè)內強師集結,手把手帶你蛻變精英
        請您保持通訊暢通,專屬學習老師24小時內將與您1V1溝通
        免費領取
        今日已有369人領取成功
        劉同學 138****2860 剛剛成功領取
        王同學 131****2015 剛剛成功領取
        張同學 133****4652 剛剛成功領取
        李同學 135****8607 剛剛成功領取
        楊同學 132****5667 剛剛成功領取
        岳同學 134****6652 剛剛成功領取
        梁同學 157****2950 剛剛成功領取
        劉同學 189****1015 剛剛成功領取
        張同學 155****4678 剛剛成功領取
        鄒同學 139****2907 剛剛成功領取
        董同學 138****2867 剛剛成功領取
        周同學 136****3602 剛剛成功領取
        相關推薦HOT
        广宁县| 青州市| 上犹县| 龙海市| 合肥市| 阜平县| 攀枝花市| 额尔古纳市| 二连浩特市| 平顶山市| 绥德县| 鹰潭市| 手游| 卓尼县| 香格里拉县| 任丘市| 万山特区| 同仁县| 全州县| 越西县| 安徽省| 黔西县| 揭阳市| 汉源县| 右玉县| 香格里拉县| 济源市| 达日县| 文昌市| 保靖县| 灵石县| 波密县| 若尔盖县| 阿克苏市| 石楼县| 凤城市| 都兰县| 莫力| 深泽县| 临西县| 鄱阳县|