The first step is very simple. You can directly search for Bingbing’s photos by going to a certain degree.
Right-click on the picture you like, open the picture in a new tab, and copy the url above, as shown in the picture:
Use requests.get(url).content to get the image, and use with open to save it locally.
I selected 3 Bingbing GIFs and saved them in a list and randomly returned one. It is easy for you to expand the Bingbing library. The code is as follows.
def getbb(): w0='https://img1.baidu.com/it/u=1762637264,598758602&fm=26&fmt=auto&gp=0.jpg' w1='https://img1.baidu.com/it/u=2231058723,1803013600&fm=11&fmt=auto&gp=0.jpg' w2='https://img0.baidu.com/it/u=3960011140,3634140813&fm=11&fmt=auto&gp=0.jpg' wlist=[w0,w1,w2] global i i=random.randint(0,2)#随机选取一个冰冰动图 url=wlist[i] req=requests.get(url).content with open(f'wbb{i}.gif','wb') as p: p.write(req)
The confession words here are what you want to say to Bingbing If so, you can type it yourself. Of course, if you are too lazy to speak your own words, the editor will also automatically crawl literary poems on the Internet for you. The more poet-like you are, the more elegant you will be.
This function is also encapsulated into a function as follows:
def getwords(): texts = [] url = 'https://www.duanwenxue.com/huayu/lizhi/list_{}.html'.format(random.randint(1,114)) response = requests.get(url) texts.append(response.text) articles = [] for text in texts: soup = BeautifulSoup(text,'lxml') arttis = soup.find('div', class_='list-short-article').find_all('a', {'target': "_blank"}) # 寻找情话内容 # 通过列表推导式以及for循环获取到每个a标签里面的text内容并通过strip去除空格 articles.extend([arttis[i].text.strip() for i in range(len(arttis))]) todaywords = articles[random.randint(0, len(articles)-1)] # 随机选取其中一条情话 return todaywords
The next step is to get to the point. You have spoken to Bingbing, and you still want Bingbing to reply to you. How do you do this?
Here, an intelligent robot is used to simulate Bingbing and generate reply content.
There are many intelligent chat robots now. It is recommended that if you have money, you can choose Turing robot, and if you are free, you can use Qingyunke.
This article is implemented using Qingyunke. No registration is required, just call the interface directly, which is very convenient.
Encapsulate it into a function, input confession words, and automatically return intelligent dialogue:
def qingyunke(msg): url = f'http://api.qingyunke.com/api.php?key=free&appid=0&msg={msg}' html = requests.get(url) return html.json()["content"]
Readers who are interested can try this Function, if you use the sao words crawled in the second step as the input msg of the function, a very interesting thing will happen:
The last step is to ask Bingbing to send you a private message and attach her beautiful photos~
This can be done using a common email address, such as 163 email or QQ email.
Take 163 mailbox as an example, click Settings:
Click POP3/SMTP/IMAP:
Click to start the IMAP/SMTP service:
An authorization code will be generated. Copy this authorization code and use it later.
The following is the code I wrote. You only need to fill in your account number and authorization code.
def sendemail(): msgword = getwords() res = qingyunke(msgword) xhx='你的163邮箱账号'#你实际使用的163邮箱账号 pwd = '你的授权密码'#刚刚生成的163授权密码 wy163list=[xhx]#收件人列表,可以扩充 host_server = 'smtp.163.com' #163邮箱smtp服务器 sender = f'{xhx}@163.com' #发件人邮箱 receiver = f'{wy163list[0]}@163.com'#收件人 mail_title = '冰冰向您发送了新邮件' #邮件标题 #邮件正文内容 #为保证接口稳定,调用频率请控制在200次/10分钟 mail_content = f"亲爱的{wy163list[0]},我是冰冰,<p>上次收到你给我的来信:<p>{msgword}<p>我很感动,特意给你回信并附上冰冰的美照哦~<p>现在我想对你说:<p>{res}<p>您好,<p>欢迎关注我的CSDN个人账号以获取最新创意好文,<p>开启python魔法之旅:</p> <p><a href='https://blog.csdn.net/x978404178?spm=1001.2100.3001.5343'>点击此处进入CSDN</a></p>" msg = MIMEMultipart() #将图片显示在正文 global i with open(f'wbb{i}.gif', 'rb') as f: #图片添加到正文 msgImage = MIMEImage(f.read()) # 定义图片ID msgImage.add_header('Content-ID', '<image1>') msg.attach(msgImage) msg["Subject"] = Header(mail_title,'utf-8') msg["From"] =Header("冰冰","utf-8") msg["To"] = receiver msg.attach(MIMEText(mail_content,'html')) try: smtp = SMTP_SSL(host_server) # ssl登录连接到邮件服务器 smtp.set_debuglevel(1) # 0是关闭,1是开启debug smtp.ehlo(host_server) # 跟服务器打招呼,告诉它我们准备连接,最好加上这行代码 smtp.login(sender,pwd) smtp.sendmail(sender,receiver,msg.as_string()) smtp.quit() print("邮件发送成功") except smtplib.SMTPException: print("无法发送邮件")
到这里呢,本文就该告一段落了,小编这里把整体代码都奉上啦,欢迎大家动手实践,有问题可以随时私我噢~
# -*- coding: utf-8 -*- from bs4 import BeautifulSoup import random import requests from smtplib import SMTP_SSL import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header from email.mime.image import MIMEImage def getbb(): w0='https://img1.baidu.com/it/u=1762637264,598758602&fm=26&fmt=auto&gp=0.jpg' w1='https://img1.baidu.com/it/u=2231058723,1803013600&fm=11&fmt=auto&gp=0.jpg' w2='https://img0.baidu.com/it/u=3960011140,3634140813&fm=11&fmt=auto&gp=0.jpg' wlist=[w0,w1,w2] global i i=random.randint(0,2)#随机选取一个冰冰动图 url=wlist[i] req=requests.get(url).content with open(f'wbb{i}.gif','wb') as p: p.write(req) def getwords(): texts = [] url = 'https://www.duanwenxue.com/huayu/lizhi/list_{}.html'.format(random.randint(1,114)) response = requests.get(url) texts.append(response.text) articles = [] for text in texts: soup = BeautifulSoup(text,'lxml') arttis = soup.find('div', class_='list-short-article').find_all('a', {'target': "_blank"}) # 寻找情话内容 # 通过列表推导式以及for循环获取到每个a标签里面的text内容并通过strip去除空格 articles.extend([arttis[i].text.strip() for i in range(len(arttis))]) todaywords = articles[random.randint(0, len(articles)-1)] # 随机选取其中一条情话 return todaywords def qingyunke(msg): url = f'http://api.qingyunke.com/api.php?key=free&appid=0&msg={msg}' html = requests.get(url) return html.json()["content"] def sendemail(): msgword = getwords() res = qingyunke(msgword) xhx='你的163邮箱账号'#你实际使用的163邮箱账号 pwd = '你的授权密码'#刚刚生成的163授权密码 wy163list=[xhx]#收件人列表,可以扩充 host_server = 'smtp.163.com' #163邮箱smtp服务器 sender = f'{xhx}@163.com' #发件人邮箱 receiver = f'{wy163list[0]}@163.com'#收件人 mail_title = '冰冰向您发送了新邮件' #邮件标题 #邮件正文内容 #为保证接口稳定,调用频率请控制在200次/10分钟 mail_content = f"亲爱的{wy163list[0]},我是冰冰,<p>上次收到你给我的来信:<p>{msgword}<p>我很感动,特意给你回信并附上冰冰的美照哦~<p>现在我想对你说:<p>{res}<p>您好,<p>欢迎关注我的CSDN个人账号以获取最新创意好文,<p>开启python魔法之旅:</p> <p><a href='https://blog.csdn.net/x978404178?spm=1001.2100.3001.5343'>点击此处进入CSDN</a></p>" msg = MIMEMultipart() #将图片显示在正文 global i with open(f'wbb{i}.gif', 'rb') as f: #图片添加到正文 msgImage = MIMEImage(f.read()) # 定义图片ID msgImage.add_header('Content-ID', '<image1>') msg.attach(msgImage) msg["Subject"] = Header(mail_title,'utf-8') msg["From"] =Header("冰冰","utf-8") msg["To"] = receiver msg.attach(MIMEText(mail_content,'html')) try: smtp = SMTP_SSL(host_server) # ssl登录连接到邮件服务器 smtp.set_debuglevel(1) # 0是关闭,1是开启debug smtp.ehlo(host_server) # 跟服务器打招呼,告诉它我们准备连接,最好加上这行代码 smtp.login(sender,pwd) smtp.sendmail(sender,receiver,msg.as_string()) smtp.quit() print("邮件发送成功") except smtplib.SMTPException: print("无法发送邮件") if __name__ == '__main__': getbb() sendemail()
运行时间大概在30s~1min30s哦,快登录你的邮箱查看冰冰给你的悄悄话吧。
效果如下:
好了,各位有没有get到冰冰呢?欢迎在下方评论区留言讨论哦。
本文基于Python网络爬虫,抓取了王冰冰靓女的动图图片,之后利用网络爬虫技术获取了文学诗篇网站的表白桥段,通过青云客平台,打造了一款智能机器人模拟冰冰回信,并且基于邮箱服务器,模拟冰冰向自己发送新邮件,每天打开邮箱,都可以收到女神的邮箱,心情美滋滋~如此有趣的项目,快快来尝试吧!
The above is the detailed content of Teach you step by step how to use Python web crawler + automation to create your own virtual female ticket (source code attached). For more information, please follow other related articles on the PHP Chinese website!