2016-08-17 86 views
-1

我一直在試圖導入一個名爲requests的模塊,它位於site-packages文件夾中。它是通過點安裝,但每次我嘗試導入它時,我得到的錯誤「ImportError:沒有名爲'request'的模塊無法在站點包目錄中導入模塊?

我正在使用「導入請求」導入。

import requests 
from bs4 import BeautifulSoup 

def spider(max_pages): 
page = 1 
while page <= max_pages: 
    url = "http://www.ebay.ie/sch/Laptops-Netbooks/175672/i.html?_catref=1&_pgn=" + str(page) + "&_skc=50&rt=nc" 
    source_code = requests.get(url) 
    plain = source_code.text 
    soup = BeautifulSoup(text) 
    for link in soup.findAll('a', {'class': 'img'}): 
     href = "http://www.ebay.ie" + link.get('href') 
     title = link.string 
     print(href) 
     print(title) 
    page += 1 

spider(1) 

我想知道如果它與我的環境變量或如果我已經安裝了他們錯了。

+0

您應該使用'import requests'。我猜這是一個錯字。 – dunder

+0

仍未導入。 –

+1

我會檢查@Orions的答案。 – vyscond

回答

0

我想你已經安裝了requests模塊Python 2,但你在Python 3工作。使用以下命令爲Python 3安裝它:

python3 -m pip install requests 

來源:Python docs

0

您有一個錯字。

import request應該import requests

+1

只是修復它。!但它仍然不會導入。 –