Skip to content

Instantly share code, notes, and snippets.

@yanissi
yanissi / Batch File for Windows
Created March 6, 2019 22:23
Create Batch File for Windows for launching Pyhton Scripts
REM This is a comment
cd instabot-master/examples
like_hashtags_copy.py neonphotography
ECHO Ran first batch
PAUSE
@yanissi
yanissi / Mac Unix Executable
Created March 6, 2019 22:27
Create Mac Executable to Launch Python Scripts
#!/bin/sh
Python /Users/yanissilloul/Documents/instabot-master/examples/like_hashtags_copy.py neonphotography
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'}
url = "https://www.apple.com/shop/buy-mac/macbook"
# First we "get" the URL using requests
request = requests.get(url, headers=headers)
# Then we retrieve the content
content = request.content
# Finally, we give this content to BeautifulSoup
find_tag = soup.find(attrs={"class" : "as-macbundle-modelvariationtitle"})
print(find_tag)
# >>> <h3 class="as-macbundle-modelvariationtitle">1.2GHz Processor<br/> 256GB Storage</h3>
# This code finds the first HTML tag that has a class named "as-macbundle-modelvariationtitle"
find_text = find_tag.text
# First way is to follow the same exact way of doing than before :
price_tag = soup.find(attrs={"class" : "as-price-currentprice"})
price_text = price_tag.text
print(price_text)
# The second way is to not look for the class of the tag but for its other attribute :
price = soup.find(attrs={"class" : "as-price-currentprice"}).text.strip()
print(price)
# >>> $1,299.00
# So there you have it, the product name and its price :
product_name = soup.find(attrs={"class" : "as-macbundle-modelvariationtitle"}).text.strip()
product_price = soup.find(attrs={"class" : "as-price-currentprice"}).text.strip()
print(f"The product '{product_name}' is sold at '{product_price}'")
# >>> The product '1.2GHz Processor 256GB Storage' is sold at '$1,299.00'