0

I just made this following another tutorial and want to make one myself, but the import of requests can't not be read or is deemed as 'ModuleNotFoundError: No Module named 'requests'.

Wherever the * is that is private information.

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()

1 Answers1

0

I guess you haven't dowloaded the module. If you're using pycharm Preferences > Projects > Python Interpreter > Find the Requests module and add that.

Or you can just pip install the module from your terminal which is

pip install requests

(but if you're using different ide you need to look where you can add modules) that way you downloaded the module for calling in the script that you wrote.

I think that should do the work.