|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import os
- import requests
- import re
- url='https://zhidao.baidu.com/question/154521735.html'
- html=requests.get(url).content.decode('gbk')
- msg=re.findall('<p>(.+?)</p>',html)
- a=open('Story.txt','w',encoding='utf-8')
- for i in msg:
- if i[ :2] == '<a':
- pass
- else:
- H=re.sub('[</strong>]','',i)
- H=H+'\n'
- a.write(H)
- a.close()
- os.rename('Story.txt','S.txt')
- print('完成')
复制代码
这个完成打不出来
错误:
- SyntaxError: Non-UTF-8 code starting with '\xcd' in file F:/Python自制软件/爬虫/爬虫2/爬虫3/KKK/爬虫_1.py on line 18, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
复制代码
怎么办啊~
改成print('end')就可以
utf-8 编码里包含全世界里的所有语言的文字
gbk 编码也在 utf-8 里面。
而且我试了用 gbk 编码会报错。
所以你就写 #coding:utf-8 就行
|
|