[問題] SOUP內含奇怪的標籤?
<tr>
<th scope="row">機構院所大類:</th>
<td>合約醫療機構</td>
</tr>
<tr>
<th scope="row">醫院評鑑:</th>
<td>新制評鑑特優<BR/>新制教學評鑑優等</td>
</tr>
中間突然出現一個<BR/> 使用replace也無法處理掉
應該說,在find_all('td')時,回應:None.......
該如何處置?
----------------------------------------------------
po一下我的原始碼好了
from bs4 import BeautifulSoup
count=0
#全部
url="http://www.health.taichung.gov.tw/lp.asp?CtNode=4639&CtUnit=3723&BaseDSD=7&mp=108010&nowPage=1&pagesize=2000"
#部份
#url="http://www.health.taichung.gov.tw/lp.asp?CtNode=4639&CtUnit=3723&BaseDSD=7&mp=108010"
html=requests.get(url).content
from bs4 import BeautifulSoup
soup = BeautifulSoup(html,"html.parser")
x=soup.find_all('tr')
for i in x[2:]:
j=i.find_all('td')
p_url='http://www.health.taichung.gov.tw/'+j[1].a['href']
html_n=requests.get(p_url).content
soup_n = BeautifulSoup(html_n,"html.parser")
y=soup_n.table
item=y.find_all('table')
for br in soup.find_all('br'): br.extract()
item_title=item[0].find_all('th')
item_text=item[0].find_all('td')
temp={}
for j in range(len(item_title)):
key=(item_title[j].string).strip()[:-1]
value=(item_text[j].string)
print key, value
sleep(1)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.8.102.255
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1483940918.A.2A3.html
→
01/09 14:29, , 1F
01/09 14:29, 1F
→
01/09 14:29, , 2F
01/09 14:29, 2F
→
01/09 14:48, , 3F
01/09 14:48, 3F
→
01/09 15:21, , 4F
01/09 15:21, 4F
→
01/09 15:22, , 5F
01/09 15:22, 5F
→
01/09 15:55, , 6F
01/09 15:55, 6F
原html內很多td..........0.0
※ 編輯: coeric (101.8.102.255), 01/09/2017 16:34:51
※ 編輯: coeric (101.8.102.255), 01/09/2017 16:37:39
→
01/09 20:30, , 7F
01/09 20:30, 7F
→
01/09 20:31, , 8F
01/09 20:31, 8F
→
01/09 20:31, , 9F
01/09 20:31, 9F