Read HTML document content

Def get_html(path, city): Str1 = f.read() str2 = str1.replace(' insert ', encoding=" utF-8 ") # insert f = open(path, "r", encoding=" utF-8 ") HTML = get_html('index2.html', zhengzhou) # HTML = get_html('index2.html', Zhengzhou) # HTMLCopy the code

New Folder

Path = city os.mkdir(path) except: pass # try: Create a new folder if it does not exist. If it does, ignore it and continue.Copy the code

Save the content

F = open(city + 'index_2.html', 'a', Encoding =' utF-8 ')# f.seek(0) # f.trencate () f.rite (HTML) f.close() # Save if index_2.html already exists and needs to be empty. Need to write a clear instruction: # f.seek(0) # 0 is the document character from the 0th bit # F.runcate () # clear instructionCopy the code

Python parsing json

City = {" id ": 24, 'en' :" henan ", "cn", "henan"} # py parsing city. Cn city [' cn ']Copy the code