循环浏览页面总是得到相同的结果
Looping through pages always gets the same result
我正在尝试循环浏览页面并保存特定图像
import urllib.request
from bs4 import BeautifulSoup as bs
frontstring = 'http://www.haz.de/'
for i in range(1, 50):
url = 'http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/' \
+ 'Digitales-Daumenkino-So-waechst-das-Parkhaus#p' + str(i)
with urllib.request.urlopen(url) as page:
soup = bs(page)
galleryimage = soup.findAll('img', {'class': 'pda-fullgallery-large photo'})
for imgtag in galleryimage:
try:
imgurl = frontstring + imgtag['src']
imgname = 'img/fullgallery-large' + str(i) + '.jpg'
urllib.request.urlretrieve(imgurl, imgname)
print('saving image from ' + imgurl + ' to ' + imgname)
except Exception as e:
raise
else:
pass
然而图像总是一样的。我不知道哪里出了问题。如果我在浏览器中打开 url,它是正确的页面和图像,但汤似乎总是相同的代码。可能是一些非常愚蠢和简单的东西,但在尝试了很长时间才发现错误后我没有看到它。
http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/Digitales-Daumenkino-So-waechst-das-Parkhaus
http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/Digitales-Daumenkino-So-waechst-das-Parkhaus/(offset)/1
http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/Digitales-Daumenkino-So-waechst-das-Parkhaus/(offset)/2
http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/Digitales-Daumenkino-So-waechst-das-Parkhaus/(offset)/3
那些才是真正的url,你看到的url是由JavaScript生成的。在抓取任何网站之前,您应该禁用 JavaScrip
我正在尝试循环浏览页面并保存特定图像
import urllib.request
from bs4 import BeautifulSoup as bs
frontstring = 'http://www.haz.de/'
for i in range(1, 50):
url = 'http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/' \
+ 'Digitales-Daumenkino-So-waechst-das-Parkhaus#p' + str(i)
with urllib.request.urlopen(url) as page:
soup = bs(page)
galleryimage = soup.findAll('img', {'class': 'pda-fullgallery-large photo'})
for imgtag in galleryimage:
try:
imgurl = frontstring + imgtag['src']
imgname = 'img/fullgallery-large' + str(i) + '.jpg'
urllib.request.urlretrieve(imgurl, imgname)
print('saving image from ' + imgurl + ' to ' + imgname)
except Exception as e:
raise
else:
pass
然而图像总是一样的。我不知道哪里出了问题。如果我在浏览器中打开 url,它是正确的页面和图像,但汤似乎总是相同的代码。可能是一些非常愚蠢和简单的东西,但在尝试了很长时间才发现错误后我没有看到它。
http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/Digitales-Daumenkino-So-waechst-das-Parkhaus
http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/Digitales-Daumenkino-So-waechst-das-Parkhaus/(offset)/1
http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/Digitales-Daumenkino-So-waechst-das-Parkhaus/(offset)/2
http://www.haz.de/Hannover/Aus-der-Region/Lehrte/Fotostrecken/Digitales-Daumenkino-So-waechst-das-Parkhaus/(offset)/3
那些才是真正的url,你看到的url是由JavaScript生成的。在抓取任何网站之前,您应该禁用 JavaScrip