python2.7 print的地方报语法错误 SyntaxError: invalid syntax

zhhaibo 2017-12-29 11:05:24
# -*- coding:utf-8 -*-
import urllib
import urllib2
import re

page = 1
url = 'https://p.baidu.com/question/fbeb6162633561653235355e00/4580278?entry=home_new_content'
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = {'User-Agent': user_agent}
try:
request = urllib2.Request(url, headers=headers)
response = urllib2.urlopen(request)
content = response.read().decode('utf-8')
pattern = re.compile(
'<div.*?ans-usr">.*?<a class="auth-name.*?">(.*?)</a>.*?<div class="content-all">"(.*?)"<div.*?target="_blank">(.*?)</a>',
re.S)
items = re.findall(pattern, content)
for item in items:
print item
#print item[0],item[1],item[2],item[4]

以上两种方法输出都报错,请求大神解答,感谢。
...全文
518 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhhaibo 2017-12-29
  • 打赏
  • 举报
回复
引用 1 楼 oyljerry 的回复:
print(item) 对齐格式等
感谢楼主,找到问题了,try语句,没有except。
zhhaibo 2017-12-29
  • 打赏
  • 举报
回复
print(item) 或者pycharm执行reformat code都还是报错
oyljerry 2017-12-29
  • 打赏
  • 举报
回复
print(item) 对齐格式等

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧