[问题] 空白消除不掉?

楼主: kiloxx (名器)   2016-04-03 17:02:30
大家好:D
python自学新手,遇到问题想请教一下
from bs4 import BeautifulSoup as bs
import requests
req =
requests.get('http://mops.twse.com.tw/mops/web/t164sb04?encodeURIComponent=1&s
       tep=1&firstin=1&off=1&keyword4=&code1=&TYPEK2=&checkbtn=&queryNa
       me=co_id&TYPEK=all&isnew=true&co_id=2330&year=104&season=04')
req.encoding ='utf-8'
soup =bs(req.text,'html5lib')
table = soup.find('table', {'class': 'hasBorder'})
title =[]
num =[]
#print (table)
for tr in table.select('tr') :
if len (tr.select('td')) >0:
sub = (tr.select('td')[0].text)
subb=sub.replace('\u3000', '')
title.append(subb)
numm= str((tr.select('td')[1].text))
numm.replace(' ','')
num.append(numm)
print (num)
作者: kerwinhui (kezza)   2016-04-03 17:09:00
string 的 strip() method?
楼主: kiloxx (名器)   2016-04-03 17:19:00
我发现要另外用var = numm.replace() 再print就行了lol抱歉耍白痴lol
作者: aweimeow (喵喵喵喵 ヽ( ・∀・)ノ)   2016-04-05 23:43:00
replace 要 assign 回去原本的变量哦

Links booklink

Contact Us: admin [ a t ] ucptt.com