iT邦幫忙

0

C#爬蟲 爬到所需資料後有特殊符號

  • 分享至 

  • twitterImage

想寫一個用c#爬到統一發票的程式
https://ithelp.ithome.com.tw/upload/images/20200524/20127340porzZiCduh.jpghttps://ithelp.ithome.com.tw/upload/images/20200524/20127340lu37nUgwbQ.jpg
爬到之後第三行出現不該出現的問號和英文字母

結果↓↓↓
https://ithelp.ithome.com.tw/upload/images/20200524/20127340iNRMvuH1qc.jpg
我用過replace("?","") 也用過trim()都不行這該怎麼解決

看更多先前的討論...收起先前的討論...
試試 replace("、"," ")
bblow988 iT邦新手 5 級 ‧ 2020-05-25 00:57:31 檢舉
string head3 = list[0].SelectSingleNode("tr[4]/td/span").InnerText.Replace("`", " ");
我寫這樣也不行
bblow988 iT邦新手 5 級 ‧ 2020-05-25 00:57:45 檢舉
還是我寫法有誤?
bblow988 iT邦新手 5 級 ‧ 2020-05-25 01:24:45 檢舉
已解決
bblow988 iT邦新手 5 級 ‧ 2020-05-25 01:25:37 檢舉
string head3 =
list[0].SelectSingleNode("tr[4]/td/span").InnerText.Replace(' ','\n');
head3 = head3.Replace("、", "");
string [] final3=head3.split(' ');
foreach(string i in final3)
{
Console.WriteLine(i.Tostring());
}
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
d6672089
iT邦新手 5 級 ‧ 2020-05-29 17:02:18

你的解決辦法日後遇到其他的特殊符號,有可能也會有問題,會Replace不完
2.1.正規表示法驗證與處理
2.字串長度限制,避免不合法的長度出現
3.驗證字串是否為純數值

我要發表回答

立即登入回答