모든 공백 및 공백 문자를 제거하는 코드를 구현하려고하고 페이지에서 발생하는 상위 3 개의 영숫자를 계산합니다. 제 질문은 두 가지입니다.HTML 문자열에서 모든 공백 제거
1) 분할을 위해 사용하는 방법이 작동하지 않는 것 같습니다. 왜 작동하지 않는지 잘 모르겠습니다. 내 지식에 합류하면 스프레드는 html 소스 코드에서 공백과 공백을 모두 제거해야하지만 그렇지 않습니다 (아래의 아마존 예제에서 반환 된 첫 번째 값 참조).
2)는 most_common 작업에 대단히 익숙하지 그리고 난 "http://amazon.com"나는 다음과 같은 출력을 얻을 내 코드를 테스트 할 때 :
The top 3 occuring alphanumeric characters in the html of http://amazon.com
: [(u' ', 258), (u'a', 126), (u'e', 126)]
U 자 반환 된 most_common에 무엇을 의미 하는가를 (3) 값?
내 현재 코드 :
import requests
import collections
url = raw_input("please eneter the url of the desired website (include http://): ")
response = requests.get(url)
responseString = response.text
print responseString
topThreeAlphaString = " ".join(filter(None, responseString.split()))
lineNumber = 0
for line in topThreeAlphaString:
line = line.strip()
lineNumber += 1
topThreeAlpha = collections.Counter(topThreeAlphaString).most_common(3)
print "The top 3 occuring alphanumeric characters in the html of", url,": ", topThreeAlpha
이는 유니 코드 문자열을 의미합니다. 공백'' ".join (...)'을 사용하여'join()'하고 그냥 빈 문자열''"로 조인하면됩니다. .join (...)' – AChampion