我正在尝试下载从Beautifulsoup刮回来的图像中的图像。
在阅读其他一些例子后,我试图让这段代码工作获取错误:
f.write(requests.get(img))
TypeError: a bytes-like object is required, not 'Response
行:f.write(requests.get(img)[What goes here?])
现在给我带来了麻烦。我使用soup = BeautifulSoup(source, 'html.parser')
参考使用soup = BeautifulSoup(r.content)
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
import urllib.request
from bs4 import BeautifulSoup
import codecs
import sys
import requests
from os.path import basename
lines = open('list.txt').read().splitlines()
for designers in lines:
for i in range(1):
url = 'https://www.example.com/Listings?st=' + author + '{}'.format(i)
source = urllib.request.urlopen(url)
soup = BeautifulSoup(source, 'html.parser')
for products in soup.find_all('li', class_='widget'):
image = products.find('img', class_='lazy-load')
print(image.get('data-src'))
img = (image.get('data-src'))
with open(basename(img), "wb") as f:
f.write(requests.get(img)**[What goes here?]**)
谢谢!