爬虫板子 发表于 2021-12-09 | 更新于: 2023-02-06 | 12345678910111213141516171819202122def askURL(url): head={ "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36" } request=urllib.request.Request(url,headers=head) try: response=urllib.request.urlopen(request) html=response.read().decode("utf-8") return html except urllib.error.URLError as e: if hasattr(e,"code"): print(e.code) if hasattr(e,"reason"): print(e.reason)url="http://12345.chengdu.gov.cn/searchTelDeal?telID=21221096&class=100&WorkFPkId=6951786"html=askURL(url)print(html)f=open('output1.html', 'w', encoding='utf-8')f.write(html)print('成功')