【问题标题】:Why does is my import requests not being read? [duplicate]为什么我的导入请求没有被读取? [复制]
【发布时间】:2020-10-30 19:13:13
【问题描述】:

我只是按照另一个教程做的,想自己做一个,但是请求的导入无法读取或被视为'ModuleNotFoundError:没有名为'requests'的模块。

凡是 * 是私人信息。

import requests
from bs4 import BeautifulSoup
import smtplib

URL = 'https://www.amazon.com/Samsung-Unlocked-Fingerprint-Recognition-Long-Lasting/dp/B082XXR64G/ref=redir_mobile_desktop?ie=UTF8&aaxitk=08Egp5KhvC3f6cEe802xMg&hsa_cr_id=5004960420401&ref_=sbx_be_s_sparkle_mcd_asin_0&th=1'

headers = {"User-Agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' }

def check_price():

    page = requests.get(URL, headers=headers)

    soup = BeautifulSoup(page.content, 'html.parser')

    title = soup.find(id="productTitle").get_text()
    price = soup.find(id="priceblock_ourprice").get_text()
    converted_price = float(price[0:5])

    if(converted_price < 750 ):
        send_mail()

    print(converted_price)
    print(title.strip())

    if(converted_price < 750):
        send_mail()



def send_mail():
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.elo()
    server.starttls()
    server.elo()

    server.login('******' , '*******')

    subject = 'Price fell down!'
    body = 'Check the link: https://www.amazon.com/Samsung-Unlocked-Fingerprint-Recognition-Long-Lasting/dp/B082XXR64G/ref=redir_mobile_desktop?ie=UTF8&aaxitk=08Egp5KhvC3f6cEe802xMg&hsa_cr_id=5004960420401&ref_=sbx_be_s_sparkle_mcd_asin_0&th=1'

    msg = f"Subject: {subject}\n\n{body}"

    server.sendmail(
    '*****',
    '*******',
    msg
    )
    print('The Email has been sent!')

    server.quit()

check_price()

【问题讨论】:

  • 你安装了“requests”模块吗?

标签: python python-3.x


【解决方案1】:

我猜你还没有下载这个模块。 如果您使用的是 pycharm Preferences > Projects > Python Interpreter > 找到 Requests 模块并添加它。

或者你可以直接从终端安装模块

pip install requests

(但如果您使用不同的 ide,您需要查看可以添加模块的位置) 这样你就下载了模块来调用你编写的脚本。

我认为应该可以。

【讨论】:

    猜你喜欢
    • 2023-02-09
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    • 2019-11-05
    • 2017-01-13
    • 2015-08-08
    • 1970-01-01
    • 2019-10-06
    相关资源
    最近更新 更多