0

I am trying to figure out the number of characters in a string but for some strange reason len() is only giving me back 1. here is an example of my output

WearWorks is a haptics design company that develops products and 
experiences that communicate information through touch. Our first product, 
Wayband, is a wearable tactile navigation device for the blind and visually 
impaired.
True
1

here is my code

import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin

url="https://www.wear.works/"
response=requests.get(url)
html=response.content
soup=BeautifulSoup(html,'html.parser')

#reference https://stackoverflow.com/questions/328356/extracting-text-from-html-file-using-python
# getting rid of the script sytle in html
for script in soup(["script", "style"]):
    (script.extract())    # rip it out
    # print(script)

# get text
# grabbing the first chunk of text
text = soup.get_text()[0]
print(isinstance(text, str))
print(len(text))

print(text)
iam.Carrot
  • 4,976
  • 2
  • 24
  • 71
Bob
  • 279
  • 6
  • 13

1 Answers1

1

The problem is text = soup.get_text()[0] convert it to text = soup.get_text() have a look. You're slicing a string to get the first character.

iam.Carrot
  • 4,976
  • 2
  • 24
  • 71