Reputation: 271
import bs4
import requests
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
url = 'http://twitter.com'
r = requests.get(url, headers=headers)
p = bs4.BeautifulSoup(r.text, 'html.parser')
p.js-signup
When I put p.js-signup
into the python shell it returns
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
p.js-signup
NameError: name 'signup' is not defined
I am quite new to this, so i'm not sure what I've done wrong, other css things that don't have '-' in them work fine
Upvotes: 1
Views: 62
Reputation: 526
With python, p.js-signup
is the opration p.js
minus signup
. It raises the error you have becaus signup
does not exists.
NameError: name 'signup' is not defined
If you want to get the element <js-lookup>
you have to use find()
as explained in the documentation.
If js-lookup
is a CSS class: https://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-by-css-class
Upvotes: 2
Reputation: 4603
The code p.js-signup
means the following:
p.js - signup
So you are trying to subtract signup
from p.js
, but there is no variable signup
in your code and that is what the error message is telling you.
Upvotes: 2