爬虫,多个页面

from urllib.request import Request,urlopen

for i in range(3):
    url = 'http://hao123.zongheng.com/store/c0/w0/s0/p{0}/all.html'.format(i+1)
    r = Request(url)
    html = urlopen(r).read().decode()
    filename = '网页' + str(i+1) + '.html'
    with open(filename,'w',encoding='utf-8') as f:
        f.write(html)
    
print(html)

 

你可能感兴趣的:(python,爬虫,scrapy)