免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 26402 | 回复: 1
打印 上一主题 下一主题

为啥re.findall的结果出现 多余的, " 等? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2021-04-20 19:14 |只看该作者 |倒序浏览
import requests
import re
url = 'http://www.shubang.net/book/66_2151.html'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36'}
web_data = requests.get(url, headers=headers)
web_data.encoding = 'utf-8'
txt = web_data.text
items = re.findall(r'line_en\" \>(.*)<|line_cn\" title=\"(.*)\"', txt)   
for item in items:
    print(item)

结果如下所示
。。。。。
('&#34;It doesn&#39;t look new. It looks old,&#34; one of the boys said.', '')('', '“房子一点也不新,旧死了,”其中一个男孩说。')('It just couldn&#39;t be.', '')('', '绝对不可能。')('The other members of his family turned to stare at me.', '')('', '其他人都把目光转向了我。')
............


请问:
1.上面的 ') , ( 是哪来的?
2.couldn't 变成了 couldn&#39;  是咋回事?


论坛徽章:
0
2 [报告]
发表于 2021-04-21 11:24 |只看该作者
知道了, 要用 replace 函数 做替换
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP