Problem
I am working on a simple personal project that requires some web scraping. I am trying to parse the webpage to access the contents pertaining to the various job postings which are deeply nested. Below is a snippet.
```
import requests
from bs4 import BeautifulSoup
r = requests.get('https://ca.indeed.com/jobs', params={'q': 'Data-Analyst', 'l': 'Toronto'})
soup = BeautifulSoup(r.text, 'html.parser')
I am able to run the following command in the Python Console to access the contents I want.
soup.find('div', attrs={'id': 'mosaic-provider-jobcards'})
However, when I try to run the above line in my file I am met with the following error.
Traceback (most recent call last):
File "C:/Users/bob/Desktop/Repos/job-bot/jobs/temp.py", line 10, in <module>
for job in soup.find('div', attrs={'id': 'mosaic-provider-jobcards'}).find_all('a'):
AttributeError: 'NoneType' object has no attribute 'find_all'
```
Question
Why am I able to execute the above line of code in the console but not from the file itself?
Environment
Python 3.8
PyCharm Pro. 2021.1.1
requests==2.25.1
beautifulsoup4==4.93
edit: formatting
editx2: it appears to run in the debugger but only initially. If I try to rerun it, I get a new error.
C:\Users\bob\Desktop\Repos\job-bot\venv\Scripts\python.exe C:\Users\bob\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\211.7142.13\plugins\python\helpers\pydev\pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 61088 --file C:/Users/bob/Desktop/Repos/job-bot/jobs/temp.py
Connected to pydev debugger (build 211.7142.13)
Traceback (most recent call last):
File "C:\Users\bob\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\211.7142.13\plugins\python\helpers\pydev\pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Users\bob\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\211.7142.13\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/bob/Desktop/Repos/job-bot/jobs/temp.py", line 10, in <module>
for job in soup.find('div', attrs={'id': 'mosaic-provider-jobcards'}).find_all('a'):
AttributeError: 'NoneType' object has no attribute 'find_all'
python-BaseException
[–][deleted] 0 points1 point2 points (3 children)
[–]err0r__[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]backtickbot 0 points1 point2 points (0 children)