鱼C论坛

 找回密码
 立即注册
查看: 1230|回复: 1

[已解决]':' expected错误

[复制链接]
发表于 2022-2-14 11:12:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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):


  1. import requests
  2. import re
  3. import jieba
  4. import json

  5. fg = 1
  6. f = []
  7. urll = "https://so.gushiwen.cn/gushi/tangshi.aspx"
  8. headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0"}
  9. html = requests.get(urll, headers=headers).text
  10. hh = re.findall("/shiwenv_[\d\D]{17}", html)
  11. for fff in hh:
  12.     url = "https://so.gushiwen.cn" + fff
  13.     html = requests.get(url, headers=headers).text
  14.     for i in re.findall("<meta name="description"content="[\d\D]+。" />",html):
  15.         for c in re.findall("t="[\d\D]+"",i):
  16.             e = c[3:len(c) - 1]
  17.             aa = jieba.lcut(e)
  18.             for d in aa:
  19.                 if d != "," and d != "。" and d != ":" and d != "!" and d != "?" and d != "(" and d != ")" and d != "(" and d != ")" and d != ":" and d != " ":
  20.                     f.append(d)
  21.     print("第" + str(fg) + "首诗文分析成功")
  22.     fg += 1

  23. with open("data.json", mode='w', encoding="utf-8") as fd:
  24.     fd.write(json.dumps(f, ensure_ascii=False))
复制代码
最佳答案
2022-2-14 19:23:51
因为你字符串里面的双引号跟外面的双引号冲突了,把字符串外面的双引号改成单引号就行

  1. import requests
  2. import re
  3. import jieba
  4. import json

  5. fg = 1
  6. f = []
  7. urll = "https://so.gushiwen.cn/gushi/tangshi.aspx"
  8. headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0"}
  9. html = requests.get(urll, headers=headers).text
  10. hh = re.findall("/shiwenv_[\d\D]{17}", html)
  11. for fff in hh:
  12.     url = "https://so.gushiwen.cn" + fff
  13.     html = requests.get(url, headers=headers).text
  14.     for i in re.findall('<meta name="description"content="[\d\D]+。" />',html):                              #   改了这行
  15.         for c in re.findall('t="[\d\D]+"',i):                                                                                      #改了这行
  16.             e = c[3:len(c) - 1]
  17.             aa = jieba.lcut(e)
  18.             for d in aa:
  19.                 if d != "," and d != "。" and d != ":" and d != "!" and d != "?" and d != "(" and d != ")" and d != "(" and d != ")" and d != ":" and d != " ":
  20.                     f.append(d)
  21.     print("第" + str(fg) + "首诗文分析成功")
  22.     fg += 1

  23. with open("data.json", mode='w', encoding="utf-8") as fd:
  24.     fd.write(json.dumps(f, ensure_ascii=False))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-2-14 19:23:51 | 显示全部楼层    本楼为最佳答案   
因为你字符串里面的双引号跟外面的双引号冲突了,把字符串外面的双引号改成单引号就行

  1. import requests
  2. import re
  3. import jieba
  4. import json

  5. fg = 1
  6. f = []
  7. urll = "https://so.gushiwen.cn/gushi/tangshi.aspx"
  8. headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0"}
  9. html = requests.get(urll, headers=headers).text
  10. hh = re.findall("/shiwenv_[\d\D]{17}", html)
  11. for fff in hh:
  12.     url = "https://so.gushiwen.cn" + fff
  13.     html = requests.get(url, headers=headers).text
  14.     for i in re.findall('<meta name="description"content="[\d\D]+。" />',html):                              #   改了这行
  15.         for c in re.findall('t="[\d\D]+"',i):                                                                                      #改了这行
  16.             e = c[3:len(c) - 1]
  17.             aa = jieba.lcut(e)
  18.             for d in aa:
  19.                 if d != "," and d != "。" and d != ":" and d != "!" and d != "?" and d != "(" and d != ")" and d != "(" and d != ")" and d != ":" and d != " ":
  20.                     f.append(d)
  21.     print("第" + str(fg) + "首诗文分析成功")
  22.     fg += 1

  23. with open("data.json", mode='w', encoding="utf-8") as fd:
  24.     fd.write(json.dumps(f, ensure_ascii=False))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-30 05:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表