最近学习python爬虫,写了一个小例子.主要用来爬取bing壁纸.
源码如下:
‘’’
import requests
from bs4 import BeautifulSoup
import re
import os
from urllib.request import urlretrieve
import time
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
class BingImgSave:
def __init__(self):
self.user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
self.headers={'User-Agent':self.user_agent}
self.baseurl='https://bing.ioliu.cn/'
self.nextpage = 0
def getHtml(self, urls):
r = requests.get(urls, headers=self.headers)
print(type(r))
return r
def parseHtml(self, response):
soup = BeautifulSoup(response.text, 'lxml', from_encoding='utf-8')
items = soup.find_all('div', class_='item')
# urltail = soup.find('div', class_='page').find(href=re.compile('/?p=')).ge

本文介绍了一个使用Python爬虫从Bing获取壁纸的小项目,代码简洁且实战有效,适用于Python3.7环境。同时,项目包含了通过邮件发送信息的功能,需要注意SMTP邮箱的配置。
最低0.47元/天 解锁文章
1025

被折叠的 条评论
为什么被折叠?



