Python3抓取页面信息,网络编程,简单发送QQ邮件

数据收集,数据整理,数据描述,数据分析

# 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)

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值