I am learning web scraping and I installed requests-html
. Now I ran this script I saw in a tutorial, and can't get it to work. I don't understand as it is a part of the standard library. I tried pip install email
but it just returned another error:
'ERROR: No matching distribution found for email'.
I ran the code in a shell and chromium
got installed for render()
function as it was supposed to. pyppeteer
was timing out for some reason so I had to declare html.render(timeout=60)
, it then worked but I still can't get it to work if I use script instead of IDLE shell.
This is the code below:
from requests_html import HTMLSession
session = HTMLSession()
url = 'https://www.youtube.com/channel/UC8tgRQ7DOzAbn9L7zDL8mLg/videos'
r = session.get(url)
r.html.render(sleep=1, keep_page=True, scrolldown=1)
#take the rendered html and find the element that we are interested in
videos = r.html.find('#video-title')
#loop through those elements extracting the text and link
for item in videos:
video = {
'title': item.text,
'link': item.absolute_links
}
print(video)
This is the traceback:
Traceback (most recent call last):
File "D:/Python/requests-render-demo.py", line 1, in <module>
from requests_html import HTMLSession
File "C:\Python39\lib\site-packages\requests_html.py", line 9, in <module>
import pyppeteer
File "C:\Python39\lib\site-packages\pyppeteer\__init__.py", line 15, in <module>
from importlib_metadata import version
File "C:\Python39\lib\site-packages\importlib_metadata\__init__.py", line 7, in <module>
import email
File "D:/Python\email.py", line 1, in <module>
import smtplib
File "C:\Python39\lib\smtplib.py", line 47, in <module>
import email.utils
ModuleNotFoundError: No module named 'email.utils'; 'email' is not a package ```