Я посетил https://mumbai.craigslist.org/, и обнаружил, что нет <a class="txt">
, только <span class="txt">
, поэтому я думаю, что вы можете попробовать это:
def word_count(url):
wordlist = []
source_code = requests.get(url)
source=BeautifulSoup(source_code.text, features="html.parser")
for post_text in source.findAll('span', {'class':'txt'}):
word_string=post_text.text
if word_string is not None:
word = word_string.lower().split ()
for each_word in word:
print(each_word)
wordlist.append(each_word)
else:
print("None")
будет выводиться правильно:
community
activities
artists
childcare
classes
events
general
...
Надеюсь, что это поможет вам, и прокомментируйте, если у вас есть дополнительные вопросы. :)