import cchardetimport cchardet
import urllib.request
import os
def get_page(url):
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36')
response = urllib.request.urlopen(req)
html = response.read()
enc = cchardet.detect(html)
enc = enc['encoding']
html = html.decode(enc)
print(html)
a = html.find('thisclass __web-inspector-hide-shortcut__')
b = html.find('<',a)
print(html[a:b])
def find_img (url):
pass
def save_img(name,img_addrs):
pass
def download_mm(name='tupian',pages = 10):
os.mkdir(name)
os.chdir(name)
url = 'https://www.tupianzj.com/meinv/xinggan'
page_num = int(get_page(url))
for i in range(pages):
page_num -= i
page_url = url +'list_176_'+str(page_num)+'.html'
img_addrs = find_img (page_url)
save_img(name,img_addrs)
if __name__ == '__main__':
download_mm()
|