|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
返回这样的错误,是什么原因,可以给我解释一下吗,谢谢大家
',' or ')' expected15行
':' expected 15行
':' expected16行
即下面这两行
for i in re.findall("<meta name="description"content="[\d\D]+。" />",html):
for c in re.findall("t="[\d\D]+"",i):
- import requests
- import re
- import jieba
- import json
- fg = 1
- f = []
- urll = "https://so.gushiwen.cn/gushi/tangshi.aspx"
- headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0"}
- html = requests.get(urll, headers=headers).text
- hh = re.findall("/shiwenv_[\d\D]{17}", html)
- for fff in hh:
- url = "https://so.gushiwen.cn" + fff
- html = requests.get(url, headers=headers).text
- for i in re.findall("<meta name="description"content="[\d\D]+。" />",html):
- for c in re.findall("t="[\d\D]+"",i):
- e = c[3:len(c) - 1]
- aa = jieba.lcut(e)
- for d in aa:
- if d != "," and d != "。" and d != ":" and d != "!" and d != "?" and d != "(" and d != ")" and d != "(" and d != ")" and d != ":" and d != " ":
- f.append(d)
- print("第" + str(fg) + "首诗文分析成功")
- fg += 1
- with open("data.json", mode='w', encoding="utf-8") as fd:
- fd.write(json.dumps(f, ensure_ascii=False))
复制代码
因为你字符串里面的双引号跟外面的双引号冲突了,把字符串外面的双引号改成单引号就行
- import requests
- import re
- import jieba
- import json
- fg = 1
- f = []
- urll = "https://so.gushiwen.cn/gushi/tangshi.aspx"
- headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0"}
- html = requests.get(urll, headers=headers).text
- hh = re.findall("/shiwenv_[\d\D]{17}", html)
- for fff in hh:
- url = "https://so.gushiwen.cn" + fff
- html = requests.get(url, headers=headers).text
- for i in re.findall('<meta name="description"content="[\d\D]+。" />',html): # 改了这行
- for c in re.findall('t="[\d\D]+"',i): #改了这行
- e = c[3:len(c) - 1]
- aa = jieba.lcut(e)
- for d in aa:
- if d != "," and d != "。" and d != ":" and d != "!" and d != "?" and d != "(" and d != ")" and d != "(" and d != ")" and d != ":" and d != " ":
- f.append(d)
- print("第" + str(fg) + "首诗文分析成功")
- fg += 1
- with open("data.json", mode='w', encoding="utf-8") as fd:
- fd.write(json.dumps(f, ensure_ascii=False))
复制代码
|
|