Baidu Post Bar reptiles applet source code

_ * _ Coding :: # UTF_8 _ * _ 
Import urllib.request 
Import urllib.parse 
Import os 
url = ' http://tieba.baidu.com/f? ' 
Start = int (the INPUT ( " Please enter the starting page number: " )) 
end = int (the iNPUT ( " Please enter an end page number: " )) 
name = the iNPUT ( " Please enter the name attached to a search bar: " ) 
NAME1 = urllib.parse.quote (name) 
num1 = (Start- 1 ) * 50 
num2 = (END- . 1 ) * 50 
IF not os.path.exists(name):
    path = r'E:\python'
    os.mkdir(path+name)
for i in range(start,end):
    data={
    'kw':name1,
    'ie':'utf-8',
    'pn':i,
    }
    headers={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
    }
    data=urllib.parse.urlencode(data)
    url+=data
    request=urllib.request.Request(url=url,headers=headers)
    response=urllib.request.urlopen(request)
    filename=name+'_'+str(i)+".html"
    filepath=path+name+'/'+filename
    with open(filepath,'wb') as fp:
        fp.write(response.read())
        print("{N} completion of the download page " .format (= n-I))

 

Guess you like

Origin www.cnblogs.com/ybl20000418/p/11609596.html