python爬虫 如何让删除爬取文本前的 /u3000 也就是全角空格符。

import requests
from lxml import html
import time

headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4094.1 Safari/537.36'}
url = 'http://finance.jrj.com.cn/2018/01/01200423879416.shtml'


try:
        
    rep = requests.get(url, headers = headers, timeout = 5)
    time.sleep(1)
    if rep.status_code == 200:
        print("链接成功")
        con = rep.content
        sel = html.fromstring(con)
        date = sel.xpath('//div[@class="texttit_m1"]/p/text()')
        date = str(date).replace(']', '').replace('[', '').replace("'", '').replace(u'\u3000', '')
        print(date)

except Exception as e:
    print("主页::" +url + " 链接失败, 原因::", e)
    pass

无法删除爬下来文本前的 u3000 已replace

阅读 9k
3 个回答

a.replace(r"\r\n", "")
用raw字符串来表示rn

a = a.strip();
新手上路,请多包涵
a.replace(chr(0x3000),"")
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题