[英]Search for a specific word in html file in Python
我想計算在html文件中可以找到一個特定單詞的次數。 html文件是從url下載的:
with urlopen(url) as response:
source = response.read()
由於html文件中沒有特定的行,因此我在瀏覽文件中查找特定單詞時遇到了麻煩。是否有一種簡單的方法?
試試下面的代碼:
num_occ = source.count("your_specific_word")
否則,您只需要通過使用count即可通過文本中出現的次數來計算count
with urlopen(url) as response:
source = response.read()
noOfOccurances = source.count(searchWord)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.