Used the following to fix the problems (for the remaining issues, will change my code around). Sorry for the improper code format in my initial post.
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)
Thank you for your time
For question 1), you have to escape the
?in the pattern.Then the
123can be extracted from the stringQuestion 2a)
You can use
(.*?)to replacesome string, the?maens non-greedy match