<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          7個(gè)實(shí)用的Python自動(dòng)化代碼

          共 7587字,需瀏覽 16分鐘

           ·

          2023-08-02 20:34

          大家注意:因?yàn)槲⑿抛罱指牧送扑蜋C(jī)制,經(jīng)常有小伙伴說(shuō)錯(cuò)過(guò)了之前被刪的文章,比如前陣子冒著風(fēng)險(xiǎn)寫的爬蟲,再比如一些限時(shí)福利,錯(cuò)過(guò)了就是錯(cuò)過(guò)了。


          所以建議大家加個(gè)星標(biāo),就能第一時(shí)間收到推送。??


          8e6e94e8de3554eb4f2d14fcf0a85512.webp



          來(lái)源:愛數(shù)據(jù)
          關(guān)于Python有一句名言:不要重復(fù)造輪子 但是問(wèn)題有三個(gè): 1、你不知道已經(jīng)有哪些輪子已經(jīng)造好了,哪個(gè)適合你用。有名有姓的的著名輪子就400多個(gè),更別說(shuō)沒名沒姓自己在制造中的輪子 2、確實(shí)沒重復(fù)造輪子,但是在重復(fù)制造汽車。包括好多大神寫的好幾百行代碼,為的是解決一個(gè)Excel本身就有的成熟功能 3、很多人是用來(lái)抓圖,數(shù)據(jù),抓點(diǎn)圖片、視頻、天氣預(yù)報(bào)自?shī)首詷芬幌拢缓竽兀孔サ酱髷?shù)據(jù)以后做什么用呢?比如某某啤酒賣得快,然后呢?比如某某電影票房多,然后呢? 以下是經(jīng)過(guò)Python3.6.4調(diào)試通過(guò)的代碼,與大家分享:

          1396543ab09efb01a91131dd95dfd352.webp

          抓取知乎圖片,只用30行代碼
              from selenium import webdriver
          import time
          import urllib.request

          driver = webdriver.Chrome()
          driver.maximize_window()
          driver.get("https://www.zhihu.com/question/29134042")
          i = 0
          while i < 10:
              driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
              time.sleep(2)
              try:
                  driver.find_element_by_css_selector('button.QuestionMainAction').click()
                  print("page" + str(i))
                  time.sleep(1)
              except:
                  break
          result_raw = driver.page_source
          content_list = re.findall("img src=\"(.+?)\" ", str(result_raw))
          n = 0
          while n < len(content_list):
              i = time.time()
              local = (r"%s.jpg" % (i))
              urllib.request.urlretrieve(content_list[n], local)
              print("編號(hào):" + str(i))
              n = n + 1

          6d7a7775ab22f3bf5a9e5d56ba3c6e4f.webp

          沒事閑的時(shí)候,聽兩個(gè)聊天機(jī)器人互相聊天
              
              
          from time import sleep
          import requests
          s = input("請(qǐng)主人輸入話題:")
          while True:
              resp = requests.post("http://www.tuling123.com/openapi/api",data={"key":"4fede3c4384846b9a7d0456a5e1e2943""info": s, })
              resp = resp.json()
              sleep(1)
              print('小魚:', resp['text'])
              s = resp['text']
              resp = requests.get("http://api.qingyunke.com/api.php", {'key''free''appid':0'msg': s})
              resp.encoding = 'utf8'
              resp = resp.json()
              sleep(1)
              print('菲菲:', resp['content'])
          #網(wǎng)上還有一個(gè)據(jù)說(shuō)智商比較高的小i機(jī)器人,用爬蟲的功能來(lái)實(shí)現(xiàn)一下:

          import urllib.request
          import re

          while True:
              x = input("主人:")
              x = urllib.parse.quote(x)
              link = urllib.request.urlopen(
                  "http://nlp.xiaoi.com/robot/webrobot?&callback=__webrobot_processMsg&data=%7B%22sessionId%22%3A%22ff725c236e5245a3ac825b2dd88a7501%22%2C%22robotId%22%3A%22webbot%22%2C%22userId%22%3A%227cd29df3450745fbbdcf1a462e6c58e6%22%2C%22body%22%3A%7B%22content%22%3A%22" + x + "%22%7D%2C%22type%22%3A%22txt%22%7D")
              html_doc = link.read().decode()
              reply_list = re.findall(r'\"content\":\"(.+?)\\r\\n\"', html_doc)
              print("小i:" + reply_list[-1])

          fb9bb74d38e144004d91c545f3debf9f.webp

          分析唐詩(shī)的作者是李白還是杜甫

              import jieba
          from nltk.classify import NaiveBayesClassifier

          # 需要提前把李白的詩(shī)收集一下,放在libai.txt文本中。
          text1 = open(r"libai.txt""rb").read()
          list1 = jieba.cut(text1)
          result1 = " ".join(list1)
          # 需要提前把杜甫的詩(shī)收集一下,放在dufu.txt文本中。
          text2 = open(r"dufu.txt""rb").read()
          list2 = jieba.cut(text2)
          result2 = " ".join(list2)
          # 數(shù)據(jù)準(zhǔn)備
          libai = result1
          dufu = result2

          # 特征提取
          def word_feats(words):
              return dict([(word, Truefor word in words])


          libai_features = [(word_feats(lb), 'lb'for lb in libai]
          dufu_features = [(word_feats(df), 'df'for df in dufu]
          train_set = libai_features + dufu_features
          # 訓(xùn)練決策
          classifier = NaiveBayesClassifier.train(train_set)

          # 分析測(cè)試
          sentence = input("請(qǐng)輸入一句你喜歡的詩(shī):")
          print("\n")
          seg_list = jieba.cut(sentence)
          result1 = " ".join(seg_list)
          words = result1.split(" ")
          # 統(tǒng)計(jì)結(jié)果


          lb = 0
          df = 0
          for word in words:
              classResult = classifier.classify(word_feats(word))
              if classResult == 'lb':
                  lb = lb + 1
              if classResult == 'df':
                  df = df + 1

          # 呈現(xiàn)比例
          x = float(str(float(lb) / len(words)))
          y = float(str(float(df) / len(words)))
          print('李白的可能性:%.2f%%' % (x * 100))
          print('杜甫的可能性:%.2f%%' % (y * 100))

          ecd3d8849b4854d4573dc9c49eac44c1.webp

          彩票隨機(jī)生成35選7


          import random

          temp = [i + 1 for i in range(35)]
          random.shuffle(temp)
          i = 0
          list = []
          while i < 7:
              list.append(temp[i])
              i = i + 1
          list.sort()
          print('\033[0;31;;1m')
          print(*list[0:6], end="")
          print('\033[0;34;;1m', end=" ")
          print(list[-1])

          41299fd74b86853b612d417e68ff0bdd.webp

          自動(dòng)寫檢討書

          import random
          import xlrd

          ExcelFile = xlrd.open_workbook(r'test.xlsx')
          sheet = ExcelFile.sheet_by_name('Sheet1')
          i = []
          x = input("請(qǐng)輸入具體事件:")
          y = int(input("老師要求的字?jǐn)?shù):"))
          while len(str(i)) < y * 1.2:
              s = random.randint(160)
              rows = sheet.row_values(s)
              i.append(*rows)
          print(" "*8+"檢討書"+"\n"+"老師:")
          print("我不應(yīng)該" + str(x)+",", *i)
          print("再次請(qǐng)老師原諒!")
          '''
          以下是樣稿:

          請(qǐng)輸入具體事件:抽煙
          老師要求的字?jǐn)?shù):200
                  檢討書
          老師:
          我不應(yīng)該抽煙, 學(xué)校一開學(xué)就三令五申,
          一再?gòu)?qiáng)調(diào)校規(guī)校紀(jì),提醒學(xué)生不要違反校規(guī),
          可我卻沒有把學(xué)校和老師的話放在心上,
          沒有重視老師說(shuō)的話,沒有重視學(xué)校頒布的重要事項(xiàng),
          當(dāng)成了耳旁風(fēng),這些都是不應(yīng)該的。
          同時(shí)也真誠(chéng)地希望老師能繼續(xù)關(guān)心和支持我,
          并卻對(duì)我的問(wèn)題酌情處理。
          無(wú)論在學(xué)習(xí)還是在別的方面我都會(huì)用校規(guī)來(lái)嚴(yán)格要求自己,
          我會(huì)把握這次機(jī)會(huì)。
          但事實(shí)證明,僅僅是熱情投入、刻苦努力、鉆研學(xué)業(yè)是不夠的,
          還要有清醒的政治頭腦、大局意識(shí)和紀(jì)律觀念,
          否則就會(huì)在學(xué)習(xí)上迷失方向,使國(guó)家和學(xué)校受損失。
          再次請(qǐng)老師原諒!
          '''

          e5278a035047e54855aa84eee3586698.webp

          屏幕錄相機(jī),抓屏軟件

          from time import sleep
          from PIL import ImageGrab

          m = int(input("請(qǐng)輸入想抓屏幾分鐘:"))
          m = m * 60
          n = 1
          while n < m:
              sleep(0.02)
              im = ImageGrab.grab()
              local = (r"%s.jpg" % (n))
              im.save(local, 'jpeg')
              n = n + 1

          c055edaf05740a0530e0c908c605cd2d.webp

          制作Gif動(dòng)圖

          from PIL import Image

          im = Image.open("1.jpg")
          images = []
          images.append(Image.open('2.jpg'))
          images.append(Image.open('3.jpg'))
          im.save('gif.gif', save_all=True, append_images=images, loop=1,)

          交流群

          時(shí)隔2個(gè)月,摸魚學(xué)習(xí)交流群再次限時(shí)開放了。

          fd85c4a9c55d36cfbb022686743e18e2.webp

          Python技術(shù)交流群(技術(shù)交流、摸魚、白嫖課程為主)又不定時(shí)開放了,感興趣的朋友,可以在下方公號(hào)內(nèi)回復(fù):666,即可進(jìn)入,一起 100 天計(jì)劃

          老規(guī)矩 ,醬友們還記得么, 右下角的 “在看” 點(diǎn)一下 如果感覺文章內(nèi)容不錯(cuò)的話,記得分享朋友圈讓更多的人知道!

          bd3c850b6c41b74adee712663f416088.webp

                

          神秘禮包獲取方式

          掃描下方二維碼添加私人微信,再送一套精華電子書! ,回復(fù) 電子書


          瀏覽 64
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  黄色日逼国产 | 97久久97欧美精品A片 | 北条麻妃在线观看一区二区 | 少女的报答-戚小怜 | 一级片观看 |