用python-MySQLdb解析MySQL数据库提取hashtag

用python-MySQLdb解析MySQL数据库提取hashtag,python,mysql,parsing,mysql-python,tweets,Python,Mysql,Parsing,Mysql Python,Tweets,我在MySQL数据库中抓取了推文,我设法连接到它并查询包含推文文本的列。现在我要做的是解析这个,并将hashtags提取到一个csv文件中 到目前为止,我的代码一直工作到最后一个循环: import re import MySQLdb # connects to database mydb = MySQLdb.connect(host='****', user='****', passwd='****', db='****') cursor = mydb.cursor(

我在MySQL数据库中抓取了推文,我设法连接到它并查询包含推文文本的列。现在我要做的是解析这个,并将hashtags提取到一个csv文件中

到目前为止,我的代码一直工作到最后一个循环:

import re
import MySQLdb

# connects to database
mydb = MySQLdb.connect(host='****',
    user='****',
    passwd='****',
    db='****')
cursor = mydb.cursor()

# queries for column with tweets text
getdata = 'SELECT text FROM bitscrape'
cursor.execute(getdata)
results = cursor.fetchall()

for i in results: 
    hashtags = re.findall(r"#(\w+)", i)
    print hashtags
我得到以下错误:TypeError:预期为字符串或缓冲区。问题出在hashtags=re.findall(r“#”(\w+),i)行中

有什么建议吗

谢谢

cursor.fetchall()
返回元组列表。从每行中提取第一个元素并将其传递给
findall()

希望有帮助

for row in results: 
    hashtags = re.findall(r"#(\w+)", row[0])