last day (14 days later) » 

6:06 AM
0
Q: Beautifulsoup error with class content Hyphens "-"?

user2661319I am used python 2.7 + BeautifulSoup 4.4.1 e = BeautifulSoup(data) s1 = e.find("div", class_="one").get_text() # Successful s2 = e.find("div", class_="two-three").get_text() # ERROR

 
AKS
What is the error?
 
It error with class content Hyphens :(
 
AKS
Do you have a stacktrace?
What doesn't work? Could you add the error you are getting with the stacktrace?
 
I successfully used the same as you, but it errow now :( ... s2 = e.find("div", attrs={'class': "two-three"}).get_text() Traceback (most recent call last): File "<stdin>", line 2, in <module> AttributeError: 'NoneType' object has no attribute 'get_text'
 
AKS
It means that there is no such element with class two-three in your data.
 
6:06 AM
There exist "two-three" elements. I have many similar problems with classes containing "-"
 
AKS
Hi
I tried in my console and couldn't see any errors.
You need to post your HTML in the question.
 
AKS
6:33 AM
first of all you need to read the response
e = str(e.read())
second it seems that some of the content is being populated using javascript hence
your html doesn't contain those tags
for example if you just try s.find('span', class_='display-price') it would work
which means the one you are trying to get aren't available in the HTML like I said earlier
 

last day (14 days later) »