xpath抓取數據值有\r\n\t時去掉的方法:https://blog.csdn.net/z564359805/article/details/101597953
抓取網頁含\r \t \n時,用normalize-space出現特殊符號有時候並不會成功,例如:['商家 \xa0廈門有限公司'],'\xa0'在網頁源碼中是' ',可以用如下方法:
方法一:修改response這種方法是修改網頁代碼裏面的數據,'\xa0'在網頁源碼中是' ',個人覺得畢竟不是篩選後的數據,修改時間會比較長
def parse(self,response):
# 修改網頁代碼裏面的數據
response = response.replace(body=response.text.replace(' ',''))
order_company = response.xpath('normalize-space(//*[@id="to"]/tbody/tr/td[3]/a/text())').extract()
item['order_company'] = order_company[0].strip()
方法二:在選擇出需要的item數據傳遞時候直接替換
item['order_company'] = order_company[0].replace("\xa0", "").strip()