使用多线程进行爬豆瓣电影top250海报图片
# -- coding: UTF-8 --
import time
import requests
import urllib.request
from bs4 import BeautifulSoup
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
# 该函数用于下载图片
# 传入函数: 网页的网址url
def download_picture(url):
headers = {
"Host": "movie.douban.com",
"Referer": "https://movie.douban.com/top250?start=225&filter=",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36",
}
# 获取网页的源代码
r = requests.get(url,headers=headers)
# 利用BeautifulSoup将获取到的文本解析成HTML
soup = BeautifulSoup(r.text, "lxml")
# 获取网页中的电影图片
content = soup.find('div', class_='article')
images = content.find_all('img')
# 获取
|