Reputation: 13206
I am trying to implement the regex query at http://regexr.com/3dnut.
This is my code so far:
from bs4 import BeautifulSoup
import urllib
r = urllib.urlopen('http://www.indeed.com/resumes?q=banking&l=london&co=GB&start=0').read()
soup = BeautifulSoup(r, "lxml")
letters = soup.search("\/r\/([^:\/\s]+)\/(\w+)")
print letters
I am expecting an array of matches, but instead I get the following error message:
Traceback (most recent call last):
File "D:/cv-scraper/main.py", line 5, in <module>
letters = soup.search("\/r\/([^:\/\s]+)\/(\w+)")
TypeError: 'NoneType' object is not callable
How do I resolve it?
Upvotes: 0
Views: 183
Reputation: 473863
There is no search()
method in BeautifulSoup
. The reason it throws this particular error is that the dot-notation has a special meaning - it is a shortcut to find()
. soup.search
is basically transformed into soup.find("search")
which would try to find a tag search
. It fails and returns None
which then is being called. What you ended up with is None("\/r\/([^:\/\s]+)\/(\w+)")
which fails with None
is not callable, of course.
Upvotes: 1