爬蟲,多個頁面

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)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章