使用Python进行WebScraping:请求导入错误

使用Python进行WebScraping:请求导入错误,python,pycharm,Python,Pycharm,我开始进入网络抓取世界。 这是我的代码: 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) 当我尝试运行代码

我开始进入网络抓取世界。 这是我的代码:

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)
当我尝试运行代码时,出现以下错误:

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

我已经在设置和安装请求上访问了项目解释器,并且已经在终端上执行了pip安装请求。

如果您使用的是Python3,请尝试使用请求

pip3 install requests

下面是我如何解决它的

我相信这可能是PyCharm的一个问题我以前也遇到过类似的问题,也许这会帮助您,因为我使用了请求而不是urllibor添加并使用它:如果您选择了不同于命令行上使用的变量,那么检查PyCharm使用的python解释器也很好。