用下面的方法解决了问题(对于剩下的问题,我会改一下代码)。很抱歉在我最初的帖子中代码格式不正确。在
import csv, re, mechanize
htmlML = br.response().read()
#escaping ? fixed the regex match
patMemberName = re.compile('<a href=/foo.php\?XID=(d+) ><font color=#000000><b>(.*) </b>')
searchMemberName = re.findall(patMemberName,htmlML)
MembersCsv = 'path-to-csv'
MemberWriter = csv.writer(open(MembersCsv, 'wb')) #adding b fixed the \n in csv
for i in searchMemberName:
MemberWriter.writerow(i)
print (i)
谢谢你抽出时间
对于问题1),您必须转义模式中的
?
。在然后可以从字符串中提取
123
问题2a)
您可以使用
(.*?)
来替换some string
,即?
maens非贪婪匹配不幸的是,我现在找不到适合Python的转义序列。通常,您将用不应在“\Q…\E”中解释的元字符包装表达式。在
试着把绳子包起来重新逃逸(字符串)。所以:
相关问题 更多 >
编程相关推荐