日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python有哪些神一般的蜜汁操作?(附代碼)

有人說,“Python除了不會生孩子,Python從撩妹到裝x,無所不能!什么都會!”

為鳳城等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及鳳城網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站制作、做網(wǎng)站、外貿(mào)營銷網(wǎng)站建設(shè)、鳳城網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

  • 下載視頻?我用Python;
  • 玩跳一跳?我用Python跳到4999分;
  • 撩妹子?依然用Python;
  • 搶紅包搶火車票?沒錯還是Python;
  • 就算是整理文件,我也還是用Python……

下面就詳細跟大家分享一些Python的騷操作:

1、Python讓你不再錯過搶紅包

剛過完年經(jīng)歷了搶紅包大戰(zhàn)的大家,是不是錯過了好幾個億!?

用黑科技Python,開發(fā)一個微信小助手,從此再也不用擔(dān)心錯過巨額紅包啦!

實現(xiàn)代碼主要有兩個部分:

(1)接收紅包消息,直接從手機端微信獲取數(shù)據(jù)比較麻煩,主流的方法都是通過微信網(wǎng)頁版來獲取。

因為網(wǎng)頁版的消息接口可以被抓包分析,比較容易獲取和使用。

(2)發(fā)通知,最簡單的通知方法就是發(fā)出聲音,還嫌不夠的話,可以彈個窗。

 
 
 
  1. # 打開手機微信
  2. poco(text='微信').click()
  3. #獲取當前頁面中所有所有群聊的名稱
  4.  群聊消息的元素標識Chat_msg = poco(name='com.tencent.mm:id/d1v').offspring('com.tencent.mm:id/b6e')
  5. # 獲取當前頁面中所有群聊的名稱
  6. Chat_names = []
  7. Chat_names = list(map(lambda x: x.get_text(), Chat_msg))
  8. # 指定搶紅包的群聊名稱
  9. chat = input('請指定群聊名稱:')
  10. if chat in Chat_names:
  11.  index = Chat_names.index(chat)
  12.  # 點擊進入指定的群聊
  13.  Chat_msg[index].click()
  14. 在微信聊天頁面中,獲取當前頁面中的所有消息元素。
  15. msg_list = poco("android.widget.ListView").children()
  16. #   遍歷消息并查找紅包
  17. for msg in msg_list:
  18. # 微信紅包的標識
  19.  LuckyMoney = msg.offspring('com.tencent.mm:id/aql')
  20.  # 已失效紅包(比如已領(lǐng)取、已被領(lǐng)完)的標識
  21.  Invalid = msg.offspring('com.tencent.mm:id/aqk')
  22.  # 判斷紅包是否有效并搶起來!
  23.  if LuckyMoney:
  24.  pass
  25.     #遍歷消息并查找紅包
  26. if Invalid.exists() and (Invalid.get_text()=='已領(lǐng)取' or Invalid.get_text()=='已被領(lǐng)完'):
  27. print(f'紅包已無效,跳過……')
  28.  continue
  29. else:
  30.  print(f'發(fā)現(xiàn)一個新紅包,搶起來!')
  31.  poco("com.tencent.mm:id/d1v")
  32.  msg.click()
  33.  click_open = poco("com.tencent.mm:id/d02")
  34.  if click_open.exists():
  35.  click_open.click()
  36.  keyevent('BACK')
  37. #初始化程序
  38. from airtest.core.api import *
  39. auto_setup(__file__)
  40. from poco.drivers.android.uiautomation import AndroidUiautomationPoco
  41. poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)

2、Python幫你搶火車票

Python除了搶紅包,也是搶火車票的一把好手,說不定你當年買下的黃牛販子手里的票就是靠Python搶到的。

大家過年回家搶票是不是巨艱辛,今年過年可以寫個搶票軟件啦!

使用 Python3 抓取12306網(wǎng)站的 車票信息,及時提醒,自動下單。

 
 
 
  1. from splinter.browser import Browser
  2. from time import sleep
  3. import traceback
  4.  
  5.  
  6. class Buy_Tickets(object):
  7.     # 定義實例屬性,初始化
  8.     def __init__(self, username, passwd, order, passengers, dtime, starts, ends):
  9.         self.username = username
  10.         self.passwd = passwd
  11.         # 車次,0代表所有車次,依次從上到下,1代表所有車次,依次類推
  12.         self.order = order
  13.         # 乘客名
  14.         self.passengers = passengers
  15.         # 起始地和終點
  16.         self.starts = starts
  17.         self.ends = ends
  18.         # 日期
  19.         self.dtime = dtime
  20.         # self.xb = xb
  21.         # self.pz = pz
  22.         self.login_url = 'https://kyfw.12306.cn/otn/login/init'
  23.         self.initMy_url = 'https://kyfw.12306.cn/otn/index/initMy12306'
  24.         self.ticket_url = 'https://kyfw.12306.cn/otn/leftTicket/init'
  25.         self.driver_name = 'chrome'
  26.         self.executable_path = 'C:\Python36\Scripts\chromedriver.exe'
  27.     # 登錄功能實現(xiàn)
  28.     def login(self):
  29.         self.driver.visit(self.login_url)
  30.         self.driver.fill('loginUserDTO.user_name', self.username)
  31.         # sleep(1)
  32.         self.driver.fill('userDTO.password', self.passwd)
  33.         # sleep(1)
  34.         print('請輸入驗證碼...')
  35.         while True:
  36.             if self.driver.url != self.initMy_url:
  37.                 sleep(1)
  38.             else:
  39.                 break
  40.     # 買票功能實現(xiàn)
  41.     def start_buy(self):
  42.         self.driver = Browser(driver_name=self.driver_name, executable_path=self.executable_path)
  43.         #窗口大小的操作
  44.         self.driver.driver.set_window_size(700, 500)
  45.         self.login()
  46.         self.driver.visit(self.ticket_url)
  47.         try:
  48.             print('開始購票...')
  49.             # 加載查詢信息
  50.             self.driver.cookies.add({"_jc_save_fromStation": self.starts})
  51.             self.driver.cookies.add({"_jc_save_toStation": self.ends})
  52.             self.driver.cookies.add({"_jc_save_fromDate": self.dtime})
  53.             self.driver.reload()
  54.             count = 0
  55.             if self.order != 0:
  56.                 while self.driver.url == self.ticket_url:
  57.                     self.driver.find_by_text('查詢').click()
  58.                     count += 1
  59.                     print('第%d次點擊查詢...' % count)
  60.                     try:
  61.                         self.driver.find_by_text('預(yù)訂')[self.order-1].click()
  62.                         sleep(1.5)
  63.                     except Exception as e:
  64.                         print(e)
  65.                         print('預(yù)訂失敗...')
  66.                         continue
  67.             else:
  68.                 while self.driver.url == self.ticket_url:
  69.                     self.driver.find_by_text('查詢').click()
  70.                     count += 1
  71.                     print('第%d次點擊查詢...' % count)
  72.                     try:
  73.                         for i in self.driver.find_by_text('預(yù)訂'):
  74.                             i.click()
  75.                             sleep(1)
  76.                     except Exception as e:
  77.                         print(e)
  78.                         print('預(yù)訂失敗...')
  79.                         continue
  80.             print('開始預(yù)訂...')
  81.             sleep(1)
  82.             print('開始選擇用戶...')
  83.             for p in self.passengers:
  84.  
  85.                 self.driver.find_by_text(p).last.click()
  86.                 sleep(0.5)
  87.                 if p[-1] == ')':
  88.                     self.driver.find_by_id('dialog_xsertcj_ok').click()
  89.             print('提交訂單...')
  90.             # sleep(1)
  91.             # self.driver.find_by_text(self.pz).click()
  92.             # sleep(1)
  93.             # self.driver.find_by_text(self.xb).click()
  94.             # sleep(1)
  95.             self.driver.find_by_id('submitOrder_id').click()
  96.             sleep(2)
  97.             print('確認選座...')
  98.             self.driver.find_by_id('qr_submit_id').click()
  99.             print('預(yù)訂成功...')
  100.         except Exception as e:
  101.             print(e)
  102.  
  103.  
  104.  
  105.  
  106. if __name__ == '__main__':
  107.     # 用戶名
  108.     username = 'xxxx'
  109.     # 密碼
  110.     password = 'xxx'
  111.     # 車次選擇,0代表所有車次
  112.     order = 2
  113.     # 乘客名,比如passengers = ['丁小紅', '丁小明']
  114.     # 學(xué)生票需注明,注明方式為:passengers = ['丁小紅(學(xué)生)', '丁小明']
  115.     passengers = ['丁彥軍']
  116.     # 日期,格式為:'2018-01-20'
  117.     dtime = '2018-01-19'
  118.     # 出發(fā)地(需填寫cookie值)
  119.     starts = '%u5434%u5821%2CWUY' #吳堡
  120.     # 目的地(需填寫cookie值)
  121.     ends = '%u897F%u5B89%2CXAY' #西安
  122.  
  123.     # xb =['硬座座'] 
  124.     # pz=['成人票']
  125.  
  126.  
  127.     Buy_Tickets(username, password, order, passengers, dtime, starts, ends).start_buy()

3、Python幫你選房子

過完年很多朋友要開始租房,自己一個個曬一個個查看是不是太累?

那就寫個Python腳本吧,爬取某租房網(wǎng)站的房源信息,利用高德的 js API 在地圖上標出房源地點,劃出距離工作地點1小時內(nèi)可到達的范圍。

對比租金等,輕輕松松選出最適合的房子。

代碼:

 
 
 
  1. 鏈家的房租網(wǎng)站
  2. 兩個導(dǎo)入的包
  3. 1.requests 用來過去網(wǎng)頁內(nèi)容
  4. 2.BeautifulSoup
  5. import time
  6. import pymssql
  7. import requests
  8. from bs4 import BeautifulSoup
  9. # https://wh.lianjia.com/zufang/
  10. #獲取url中下面的內(nèi)容
  11. def get_page(url):
  12. responce = requests.get(url)
  13. soup = BeautifulSoup(responce.text,'lxml')
  14. return soup
  15. #封裝成函數(shù),作用是獲取列表下的所有租房頁面的鏈接,返回一個鏈接列表
  16. def get_links(url):
  17. responce = requests.get(url)
  18. soup = BeautifulSoup(responce.text,'lxml')
  19. link_div = soup.find_all('div',class_ = 'pic-panel')
  20. links = [div.a.get('href') for div in link_div]
  21. return links
  22. #收集一個房子的信息
  23. def get_house_info(house_url):
  24. soup = get_page(house_url)
  25. price = soup.find('span',class_='total').text
  26. unit = soup.find('span',class_= 'unit').text[1:-1]
  27. area = soup.find('p', class_ = 'lf').text
  28. house_info= soup.find_all('p',class_ = 'lf')
  29. area = house_info[0].text[3:] #字符串切片工具
  30. layout = house_info[1].text[5:]
  31. info={
  32. '價格':price,
  33. '單位':unit,
  34. '面積':area,
  35. '戶型':layout
  36. }
  37. return info
  38. #鏈接數(shù)據(jù)庫
  39. server="192.168.xx.xx" #換成自己的服務(wù)器信息
  40. user="liujiepeng"
  41. password="xxxxx" #自己的數(shù)據(jù)庫用戶名和密碼
  42. conn=pymssql.connect(server,user,password,database="house")
  43. def insert(conn,house):
  44. #sql_values = values.format(house['價格'],house['單位'],house['面積'],
  45. #house['戶型'])
  46. sql = "insert into [house].dbo.lianjia(price,unit,area,layout)values('%s','%s','%s','%s')"%(house["價格"],house["單位"],house["面積"],house["戶型"])
  47. print(sql)
  48. cursor = conn.cursor() #游標,開拓新的窗口
  49. #cursor1 = conn.cursor()
  50. cursor.execute(sql) #執(zhí)行sql語句
  51. conn.commit() #提交 ,更新sql 語句
  52. links = get_links('https://wh.lianjia.com/zufang/')
  53. count = 1
  54. for link in links:
  55. #time.sleep(2)
  56. print('獲取一個數(shù)據(jù)成功')
  57. house = get_house_info(link)
  58. insert(conn,house)
  59. print("第%s個數(shù)據(jù),存入數(shù)據(jù)庫成功!"%(count))
  60. count = count+1
  61. #print(house["價格"],end='\r')

4、Python找回女神撤回的消息

除了這些日常操作,麥教授說幾個你想不到的吧。

當自己一直喜歡的女神發(fā)給自己一個消息的時候,還沒來得及看,就撤回了。

是不是自己在心中"YY",她是不是發(fā)了什么,然后你問她的時候,她卻說沒什么。

學(xué)會Python,你可以做一個程序,把私聊撤回的信息可以收集起來并發(fā)送到個人微信的文件傳輸助手。

5、Python自己寫小游戲

用Python寫幾個小游戲玩玩也不過是幾十行代碼的事,比如寫個貪吃蛇!

還記得之前火爆一時的跳一跳,如果你早點學(xué)會Python,就可以常年占據(jù)排行榜第1了,還是全自動的效果,很有趣!

跳一跳代碼:

 
 
 
  1. from __future__ import print_function
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import matplotlib.animation as animation
  5. import math
  6. import time
  7. import os
  8. import cv2
  9. import datetime
  10. scale = 0.25
  11. template = cv2.imread('character.png')
  12. template = cv2.resize(template, (0, 0), fx=scale, fy=scale)
  13. template_size = template.shape[:2]
  14. def search(img):
  15.  result = cv2.matchTemplate(img, template, cv2.TM_SQDIFF)
  16.  min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
  17.  cv2.rectangle(img, (min_loc[0], min_loc[1]), (min_loc[0] + template_size[1], min_loc[1] + template_size[0]), (255, 0, 0), 4)
  18.  return img, min_loc[0] + template_size[1] / 2, min_loc[1] + template_size[0]
  19. def pull_screenshot():
  20.  filename = datetime.datetime.now().strftime("%H%M%S") + '.png'
  21.  os.system('mv autojump.png {}'.format(filename))
  22.  os.system('adb shell screencap -p /sdcard/autojump.png')
  23.  os.system('adb pull /sdcard/autojump.png .')
  24. def jump(distance):
  25.  press_time = distance * 1.35
  26.  press_time = int(press_time)
  27.  cmd = 'adb shell input swipe 320 410 320 410 ' + str(press_time)
  28.  print(cmd)
  29.  os.system(cmd)
  30. def update_data():
  31.  global src_x, src_y
  32.  img = cv2.imread('autojump.png')
  33.  img = cv2.resize(img, (0, 0), fx=scale, fy=scale)
  34.  img, src_x, src_y = search(img)
  35.  return img
  36. fig = plt.figure()
  37. index = 0
  38. # pull_screenshot()
  39. img = update_data()
  40. update = True 
  41. im = plt.imshow(img, animated=True)
  42. def updatefig(*args):
  43.  global update
  44.  if update:
  45.  time.sleep(1)
  46.  pull_screenshot()
  47.  im.set_array(update_data())
  48.  update = False
  49.  return im,
  50. def onClick(event): 
  51.  global update 
  52.  global src_x, src_y
  53.  
  54.  dst_x, dst_y = event.xdata, event.ydata
  55.  distance = (dst_x - src_x)**2 + (dst_y - src_y)**2 
  56.  distance = (distance ** 0.5) / scale
  57.  print('distance = ', distance)
  58.  jump(distance)
  59.  update = True
  60. fig.canvas.mpl_connect('button_press_event', onClick)
  61. ani = animation.FuncAnimation(fig, updatefig, interval=5, blit=True)
  62. plt.show()

貪吃蛇代碼:

 
 
 
  1. #!/usr/bin/env python
  2. import pygame,sys,time,random
  3. from pygame.locals import *
  4. # 定義顏色變量
  5. redColour = pygame.Color(255,0,0)
  6. blackColour = pygame.Color(0,0,0)
  7. whiteColour = pygame.Color(255,255,255)
  8. greyColour = pygame.Color(150,150,150)
  9. # 定義gameOver函數(shù)
  10. def gameOver(playSurface):
  11.  gameOverFont = pygame.font.Font('arial.ttf',72)
  12.  gameOverSurf = gameOverFont.render('Game Over', True, greyColour)
  13.  gameOverRect = gameOverSurf.get_rect()
  14.  gameOverRect.midtop = (320, 10)
  15.  playSurface.blit(gameOverSurf, gameOverRect)
  16.  pygame.display.flip()
  17.  time.sleep(5)
  18.  pygame.quit()
  19.  sys.exit()
  20. # 定義main函數(shù)
  21. def main():
  22.  # 初始化pygame
  23.  pygame.init()
  24.  fpsClock = pygame.time.Clock()
  25.  # 創(chuàng)建pygame顯示層
  26.  playSurface = pygame.display.set_mode((640,480))
  27.  pygame.display.set_caption('Raspberry Snake')
  28.  # 初始化變量
  29.  snakePosition = [100,100]
  30.  snakeSegments = [[100,100],[80,100],[60,100]]
  31.  raspberryPosition = [300,300]
  32.  raspberrySpawned = 1
  33.  direction = 'right'
  34.  changeDirection = direction
  35.  while True:
  36.  # 檢測例如按鍵等pygame事件
  37.  for event in pygame.event.get():
  38.  if event.type == QUIT:
  39.  pygame.quit()
  40.  sys.exit()
  41.  elif event.type == KEYDOWN:
  42.  # 判斷鍵盤事件
  43.  if event.key == K_RIGHT or event.key == ord('d'):
  44.  changeDirection = 'right'
  45.  if event.key == K_LEFT or event.key == ord('a'):
  46.  changeDirection = 'left'
  47.  if event.key == K_UP or event.key == ord('w'):
  48.  changeDirection = 'up'
  49.  if event.key == K_DOWN or event.key == ord('s'):
  50.  changeDirection = 'down'
  51.  if event.key == K_ESCAPE:
  52.  pygame.event.post(pygame.event.Event(QUIT))
  53.  # 判斷是否輸入了反方向
  54.  if changeDirection == 'right' and not direction == 'left':
  55.  direction = changeDirection
  56.  if changeDirection == 'left' and not direction == 'right':
  57.  direction = changeDirection
  58.  if changeDirection == 'up' and not direction == 'down':
  59.  direction = changeDirection
  60.  if changeDirection == 'down' and not direction == 'up':
  61.  direction = changeDirection
  62.  # 根據(jù)方向移動蛇頭的坐標
  63.  if direction == 'right':
  64.  snakePosition[0] += 20
  65.  if direction == 'left':
  66.  snakePosition[0] -= 20
  67.  if direction == 'up':
  68.  snakePosition[1] -= 20
  69.  if direction == 'down':
  70.  snakePosition[1] += 20
  71.  # 增加蛇的長度
  72.  snakeSegments.insert(0,list(snakePosition))
  73.  # 判斷是否吃掉了樹莓
  74.  if snakePosition[0] == raspberryPosition[0] and snakePosition[1] == raspberryPosition[1]:
  75.  raspberrySpawned = 0
  76.  else:
  77.  snakeSegments.pop()
  78.  # 如果吃掉樹莓,則重新生成樹莓
  79.  if raspberrySpawned == 0:
  80.  x = random.randrange(1,32)
  81.  y = random.randrange(1,24)
  82.  raspberryPosition = [int(x*20),int(y*20)]
  83.  raspberrySpawned = 1
  84.  # 繪制pygame顯示層
  85.  playSurface.fill(blackColour)
  86.  for position in snakeSegments:
  87.  pygame.draw.rect(playSurface,whiteColour,Rect(position[0],position[1],20,20))
  88.  pygame.draw.rect(playSurface,redColour,Rect(raspberryPosition[0], raspberryPosition[1],20,20))
  89.  # 刷新pygame顯示層
  90.  pygame.display.flip()
  91.  # 判斷是否死亡
  92.  if snakePosition[0] > 620 or snakePosition[0] < 0:
  93.  gameOver(playSurface)
  94.  if snakePosition[1] > 460 or snakePosition[1] < 0:
  95.  for snakeBody in snakeSegments[1:]:
  96.  if snakePosition[0] == snakeBody[0] and snakePosition[1] == snakeBody[1]:
  97.  gameOver(playSurface)
  98.  # 控制游戲速度
  99.  fpsClock.tick(5)
  100. if __name__ == "__main__":
  101.  main()

6、Python爬取你想要的信息

還可以用python爬取電影分析影評,用詞云進行展示效果:

寫幾行代碼浪漫一把也是可以的,你也可以把里面的字符換成愛人的名字,做成浪漫的云圖詞!

7、Python看看你朋友圈都是什么樣的人

掌握python以后,你玩微信別人也玩微信。

但是你可以得到不一樣的騷操作,幾十行代碼掌握你朋友圈都是些什么樣的人!

比如?爬取微信好友男女比例并進行可視化。

再來看看你的好友都來自哪個地方

這還不夠,來把好友的個性簽名也玩出逼格,做個創(chuàng)意的文字圖,看看大家都在說什么

溫馨小提示,如果分析的對象換成你的用戶們...是不是業(yè)績能蹭蹭上漲?

8、Python自己做小動畫

還可以用字符串跳一段MV,成為B站大佬,使用 OpenCV 處理圖片視頻,將視頻轉(zhuǎn)為字符畫序列,再在終端中播放字符動畫。

9、Python鑒黃

看看Python還能用來干嘛

《圖片就不放了 怕被舉報 自行想象》

哈哈 可以用來emmm 鑒黃!

使用 Python3 去識別圖片是否為色情圖片,利用PIL 這個圖像處理庫,會編寫算法來劃分圖像的皮膚區(qū)域。

其中涉及到Python 3 基礎(chǔ)知識,膚色像素檢測與皮膚區(qū)域劃分算法。

是不是萬萬沒想到?

10、Python AI醫(yī)療

還被用進醫(yī)療的領(lǐng)域。

典型如騰訊覓影這樣的產(chǎn)品,用于AI醫(yī)學(xué)圖像分析,在癌癥的早期識別上,人工智能對拍片的識別能力,也已經(jīng)超過人類醫(yī)生。

Python能做的好玩又實用的事情實在太多啦!


網(wǎng)站題目:Python有哪些神一般的蜜汁操作?(附代碼)
轉(zhuǎn)載注明:http://www.5511xx.com/article/cohoodo.html