Python爬虫二
import requests
import re
import os
import sys
main_url =
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62"
}
res = requests.get(url=main_url, headers=headers)
# print(res.content.decode())
print(os.getcwd() + "\crawler\crawlering_basic")
f = open(os.getcwd() + "\crawler\crawlering_basic" + "\\test1.html", "w+", encoding="utf-8")
# 在记录中文的时候,一定要输入utf-8,也就是需要输入encoding=utf-8.
f.write(res.content.decode())
f.close()