- 帖子
- 1
- 精华
- 0
- 积分
- 5
- 阅读权限
- 10
- 注册时间
- 2016-11-6
- 最后登录
- 2016-11-6
|
以下是代码
from bs4 import BeautifulSoup
import requests,urllib.request
import time
header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'}
urls = []
def get_page_link(star,end):
for each_page in range(star,end):
full_url = 'http://jandan.net/ooxx/page-{}'.format(each_page)
wb_data = requests.get(full_url)
soup = BeautifulSoup(wb_data.text,'lxml')
for pic_tag in soup.find_all('img'):
pic_link = pic_tag.get('src')
urls.append(pic_link)
return (urls)
folder_path = 'E://jiandan/'
def dl_img(url):
urllib.request.urlretrieve(url,folder_path + url[-10:])
print('Done')
for url in get_page_link(2199,2201):
dl_img(url)
time.sleep(2)
虽然想多页下载,但每次还是只能下载一页的图片,比如上面的代码中就只能下载2199那一页的图片,之后就会报错:
Traceback (most recent call last):
File "F:/python/外部包或学习视频/4周实现爬虫/课程资料/Plan-for-combating-master/week1/1_3/等会就删.py", line 28, in <module>
dl_img(url)
File "F:/p困扰很久了,求各位相助!
ython/外部包或学习视频/4周实现爬虫/课程资料/Plan-for-combating-master/week1/1_3/等会就删.py", line 24, in dl_img
urllib.request.urlretrieve(url,folder_path + url[-10:])
File "F:\python3\lib\urllib\request.py", line 198, in urlretrieve
tfp = open(filename, 'wb')
FileNotFoundError: [Errno 2] No such file or directory: 'E://jiandan/g/1112.png'
困扰很久了,求各位相助!
|
|