Python3抓取页面信息,网络编程,简单发送QQ邮件
2016-11-15 17:06
1161 查看
数据收集,数据整理,数据描述,数据分析
# coding=utf-8 import sys import urllib.request req = urllib.request.Request('https://www.baidu.com') response = urllib.request.urlopen(req) the_page=response.read() type=sys.getfilesystemencoding() #转换成本地系统编码 print(the_page.decode(type))
# coding=utf-8 import sys import urllib.request page_url="http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gbk&word=%B7%E7%BE%B0%CD%BC%C6%AC&fr=ala&ala=1&alatpl=others&pos=0" #req = urllib.request.Request(page_url) #response = urllib.request.urlopen(req) response = urllib.request.urlopen(page_url) the_page=response.read() #type=sys.getfilesystemencoding() #转换成本地系统编码 # print(the_page.decode(type)) print(the_page.decode("utf-8"))
UnicodeDecodeError 编码错误
# coding=utf-8 import sys import urllib.request page_url="http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gbk&word=%B7%E7%BE%B0%CD%BC%C6%AC&fr=ala&ala=1&alatpl=others&pos=0" req = urllib.request.Request(page_url) response = urllib.request.urlopen(req) the_page=response.read() type=sys.getfilesystemencoding() #转换成本地系统编码 print(the_page.decode("utf-8"))
import socket import sys serversocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) host = socket.gethostname() port = 9993 serversocket.bind((host,port)) serversocket.listen(5) while True: clientsocket,addr = serversocket.accept() print("link to address:%s"%str(addr)) msg="welcom to here!"+"\r\n" clientsocket.send(msg.encode("utf-8")) clientsocket.close()
import socket import sys s= socket.socket(socket.AF_INET,socket.SOCK_STREAM) host = socket.gethostname() port=9993 s.connect((host,port)) msg = s.recv(1024) s.close() print(msg.decode('utf-8'))
要想能在第三方QQ发送邮件必须获得授权码
获得授权码方法
import smtplib from email.mime.text import MIMEText __user='自己邮箱@qq.com' __pwd = '你的授权码' __to = '对方邮箱@qq.com' msg = MIMEText('Text') msg['Subject'] = "hello good morning!" msg['From'] = __user msg['To'] = __to try: s = smtplib.SMTP_SSL("smtp.qq.com",465) s.login(__user,__pwd) s.sendmail(__user,__to,msg.as_string()) s.quit() print("Success!") except smtplib.SMTPException as e: print("Failed,%s"%e)
相关文章推荐
- Python简单学习(lecture7)CGI编程、MySQL、网络编程、SMTP发送邮件
- 使用python中的smtplib库,写一个简单的发送qq邮件程序,速成!!
- Python网络编程:E-mail服务(九) 发送HTML格式邮件
- python抓取简单页面信息
- 通过python的paramiko抓取多台服务器信息,并通过html格式发送邮件到群组
- Python网络编程 获取页面中的天气信息
- Python -- 网络编程 -- 简单抓取网页
- python简单实现服务器信息自动邮件发送
- 爬虫requests库简单抓取页面信息功能实现(Python)
- python发送邮件简单示例
- Python编写发送简单html邮件代码
- Python模拟Web Fetion给好友发送信息(数据库编程模块)
- 【Python】Python使用smtplib发送简单文本邮件
- python :简单邮件发送
- Python SMTP协议发送QQ邮件
- Java网络编程之JavaMail发送邮件和接受邮件
- 基础网络编程,简单QQ
- python写的简单发送邮件的脚本
- [Python] 抓取聚划算页面商品分析页面获取商品信息并以XML格式保存到本地
- java网络编程三:基于SMTP的邮件发送客户端