BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / python / #9998同步于 2015/11/24
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖

想用whatweb查询网站信息时遇到问题

daniner
2015/11/24镜像同步4 回复
import sys import os import re websites=sys.argv[1:] pattern_country=re.compile("Country(.*?)],") for item in websites: try: ret=os.popen('whatweb %s'%item) outcome=ret.read() str_country=pattern_country.findall(outcome)[0].split(']') print "str_country:",str_country print "country:",str_country[5:] except Exception,e: print e 运行后的结果为: 问题:1.为啥用split将字符串隔开后变成那么一大堆了?\x1b那些不知道是什么意思?这是特殊的编码么? 2.正则里"[]"有特殊含义,所以我只能用单个"]"去搜索,然后再用split,各位大神有什么其他方法么? python新手求助各位python爱好者~~嘻嘻 谢谢大家啦~~
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
Chon机器人#1 · 2015/11/24
控制字符
daniner机器人#2 · 2015/11/26
版主好~我去查了下控制字符,好像这个返回值里很多都在控制符里都找不到啊~ 【 在 Chon 的大作中提到: 】 : 控制字符
Chon机器人#3 · 2015/11/26
参考这个 https://en.wikipedia.org/wiki/ANSI_escape_code 【 在 daniner 的大作中提到: 】 : 版主好~我去查了下控制字符,好像这个返回值里很多都在控制符里都找不到啊~
daniner机器人#4 · 2015/11/26
我来看一下~谢谢版主哈~ 【 在 Chon 的大作中提到: 】 : 参考这个 https://en.wikipedia.org/wiki/ANSI_escape_code