Skip to content

Commit

Permalink
issues_bug_574 无法匹配获取微博长文,尝试修复
Browse files Browse the repository at this point in the history
  • Loading branch information
二乔 committed Apr 27, 2024
1 parent bc15852 commit 241d109
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions weibo_spider/parser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ def handle_html(cookie, url):
def handle_garbled(info):
"""处理乱码"""
try:
info = (info.xpath('string(.)').replace(u'\u200b', '').encode(
sys.stdout.encoding, 'ignore').decode(sys.stdout.encoding))
if hasattr(info, 'xpath'): # 检查 info 是否具有 xpath 方法
info_str = info.xpath('string(.)') # 提取字符串内容
else:
info_str = str(info) # 若不支持 xpath,将其转换为字符串

info = info_str.replace(u'\u200b', '').encode(
sys.stdout.encoding, 'ignore').decode(sys.stdout.encoding)
return info
except Exception as e:
logger.exception(e)
Expand Down

0 comments on commit 241d109

Please sign in to comment.