简体   繁体   中英

expected string or buffer

I am writing a crawler which crawls and save the crawled information in variable i , so I did this:

my_string = i
match = re.search("\<!-- populate table from mysql database -->(.*?)\</tbody>" , my_string).group(1)    
print match

Got this error:

TypeError: expected string or buffer

Can anyone give me advice on what's the problem here?

my_string ie i is not a string (or buffer) needed by re.search .

You can convert it to a string and then do re.search :

my_string = str(i)
match = re.search(r"\<!-- populate table from mysql database -->(.*?)\</tbody>" , my_string).group(1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM