0

I am getting started to the web scraping "world". This is my code:

import urllib
import urllib.request
from bs4 import BeautifulSoup

theurl = "https://twitter.com/realdonaldtrump";
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage,"html.parser")

print (soup.title)

When I try to run the code I have the following error:

Traceback (most recent call last):
  File "C:/Users/ACC/PycharmProjects/untitled/venv/imp.py", line 2, in <module>
    import urllib.request
ImportError: No module named request

Process finished with exit code 1

I've already went to the project interpreter on settings and installed requests, and I've already did pip install requests on terminal.

nnnmmm
  • 7,964
  • 4
  • 22
  • 41
Ricardo Barbosa
  • 157
  • 2
  • 14
  • I believe this could be an issue with PyCharm (I have had similar issues before) maybe this will help you as it did me https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000410510-PyCharm-won-t-recognize-installed-module – Joshua Loader Dec 04 '19 at 14:47
  • Use ```requests``` instead of ```urllib``` – Joshua Nixon Dec 04 '19 at 14:57
  • or add this and use it: https://github.com/python/cpython/blob/3.8/Lib/urllib/request.py – Lakshya Srivastava Dec 04 '19 at 21:19
  • Also good to check which python interpreter pycharm is using, in case you have selected a different variant than the one used on the command line. – Har Feb 23 '20 at 18:40

1 Answers1

1

If you are using Python3 try using "requests" instead

pip3 install requests

Here is how I solve it ImportError: No module named requests