马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
import bs4
def open_url(url):
headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"}
r=requests.get(url,headers=headers)
return r
def main():
game_url='https://www.bilibili.com/v/game/'
res=open_url(game_url)
with open('bilibiliweb.txt','w') as f:
f.write(res.text)
if __name__=='__main__':
main()
这个编码一直出错,求解
写入编码改为 utf-8 就好了:
import requests
import bs4
def open_url(url):
headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"}
r=requests.get(url,headers=headers)
return r
def main():
game_url='https://www.bilibili.com/v/game/'
res=open_url(game_url)
with open('bilibiliweb.txt','w',encoding='utf-8') as f:
f.write(res.text)
if __name__=='__main__':
main()
|