日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

2018~2019第二学年17级信管班杨秀璋老师《大数据技术及运用》课堂python代码学习汇总(第二部分)

發布時間:2024/3/24 python 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2018~2019第二学年17级信管班杨秀璋老师《大数据技术及运用》课堂python代码学习汇总(第二部分) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、python定義類型

print "abc"strl=raw_input("please input a string:") print (strl) print (type(strl))weight=raw_input("") print(weight) print(type(weight))cj=input("please input cj:") print(cj,type(cj))

運行結果:

2、查看字符型,輸出矩陣,依次輸出字符

print range(10) print (type(range(10)))for i in range(10):print inum=[1,3,5,7,9] print num for k in num:print num str2="ayouleyang" for a in str2:print a

運行結果:

3、翻倍輸出及三角形

a="yangyou" print a print a*4for i in range(10):print "*"*i print ""for i in range(10):print "*"*(10-i) print ""

運行結果:

4、爬取網頁源代碼

import urllib import webbrowser as web url="http://news.gufe.edu.cn/html/news/201903/4325.html" #獲取該網頁的源代碼html web.open_new_tab(url)content=urllib.urlopen(url).read() print content #兩個參數:保存文件的名稱 Write寫入文件 open("ecm.html","w").write(content)

運行結果:

5、下載并保存圖片

import urllib url2="https://www.baidu.com/s?wd=%E4%BB%8A%E6%97%A5%E6%96%B0%E9%B2%9C%E4%BA%8B&tn=SE_Pclogo_6ysd4c7a&sa=ire_dl_gh_logo&rsv_dl=igh_logo_pc" urllib.urlretrieve(url2,"bd.jpg")

運行結果:

6、爬取網頁文本

from requests_html import HTMLSession session = HTMLSession() url = 'https://www.jianshu.com/p/85f4624485b9' r = session.get(url) print(r.html.text)

運行結果:

7、正則表達式獲取非為本代碼

# -*- coding: utf_8 -*- import urllib.request import reurl = "http://www.nipic.com/topic/show_6547_1.html"content = urllib.request.urlopen(url).read() print (content)#<img src="圖片地址" /> #正則表達式獲取所有圖片的地址 nums = re.findall('src="(.*?\.jpg)"', content) title=re.findall(r"<title>(.*?)</title>",content) print (title[0])i = 1 for u in nums:print (u)name = "img//yxz" + str(i) + ".jpg"print (name)i = i + 1urllib.urlretrieve(u, name)

運行結果:

8、爬取豆瓣網

from bs4 import BeautifulSoup from urllib import request # -*- coding: utf-8 -*- #爬取多頁豆瓣評分電影 url = " https://movie.douban.com/top250" content = request.urlopen(url).read()#BS解析 soup = BeautifulSoup(content, "html.parser") print (soup.title) print (soup.title.text)#爬取圖片地址 nums = soup.findAll('img') for n in nums:print (n) #爬取正文 info = soup.find_all(attrs={'class': 'item'}) for n in info:print (n.text.replace('\n', ''))print("=========================")

運行結果:

9、查看微信好友

#—*—coding:utf-8-*- import itchat itchat.login() friends=itchat.get_friends(update='Ture')[0:] print (u"昵稱",u"性別",u"省份",u"城市") for i in friends[0:]:print (i["NickName"],i["Sex"],i["Province"],i["City"])

運行結果:

10、微信自動回復

# -*- coding: utf-8 -*- import itchat import time # import time @itchat.msg_register('Text') def text_reply(msg):if not msg['FromUserName'] == myUserName: # 當消息不是由自己發出的時候# 發送一條提示給文件助手itchat.send_msg(u"[%s]收到好友@%s 的信息:%s\n" %(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(msg['CreateTime'])),msg['User']['NickName'],msg['Text']), 'filehelper')# 回復給好友return u'[自動回復]您好,我現在有事不在,一會再和您聯系。\n已經收到您的的信息:%s\n' % (msg['Text'])if __name__ == '__main__':itchat.auto_login()myUserName = itchat.get_friends(update=True)[0]["UserName"]itchat.run()

運行結果:

11、QQ好友頭像獲取

import itchat# itchat.login()#微信登錄 itchat.auto_login(hotReload=True)#自動登錄 保存登錄信息 暫時的friends = itchat.get_friends()#獲取好友列表 # print(friends)#[]列表for friend in friends:#獲取好友名字print(friend['NickName']) # {}字典 鍵值隊來取值#獲取頭像 @9102085afd09827b10569fd7272d6e0032e4febc8b4bc5a25b8c49cdb2635a19 相當于IDimg = itchat.get_head_img(userName=friend['UserName'])path = "E:\PythonMake\Wechat\images\\"+friend['NickName']+".jpg"print("正在下載:%s的信息" % friend['NickName'])with open(path,'wb') as f:f.write(img)

運行結果:

總結

以上是生活随笔為你收集整理的2018~2019第二学年17级信管班杨秀璋老师《大数据技术及运用》课堂python代码学习汇总(第二部分)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。