Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python highlights #12

Open
REIS0 opened this issue Aug 18, 2019 · 0 comments
Open

Python highlights #12

REIS0 opened this issue Aug 18, 2019 · 0 comments

Comments

@REIS0
Copy link

REIS0 commented Aug 18, 2019

This is more a request than a issue itself, the support for python still lacks some small things compared to atom, things like functions and some texts are not highlighted as it should.

Here's the code, its just a simple web scrapper so nothing really important here

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import pandas
import time

url = "https://www.amazon.com/"

#* abre o browser 
browser = webdriver.Firefox()
browser.implicitly_wait(30)

#* abre o url
browser.get(url)
search_bar = browser.find_element_by_id("twotabsearchtextbox")  # acha a search bar
search_bar.clear()

#* pesquisa na search bar
search_bar.send_keys("computer")
search_bar.submit()

#* espera um pouco a pagina carregar
time.sleep(10)
# pega o html da pagina
content = browser.page_source
soup = BeautifulSoup(content, "html.parser")

#* fecha o browser
browser.quit()

products = []
prices = []
ratings = []
#* procura em todas as classes de um produto e pega seus atributos 
for product in soup.find_all(class_="a-section a-spacing-medium"):
    # pega classe com o nome
    name = product.find(class_="a-size-medium a-color-base a-text-normal")
    # pega classe com o preco
    price = product.find(class_="a-price-whole")
    # pega classe com avaliacao
    rating = product.find(class_="a-icon-alt")
    # caso nao tiver nome ignorar
    if name != None:
        products.append(name.text)
        prices.append(price.text)
        ratings.append(rating.text)

#* cria um dataframe
df = pandas.DataFrame({
    "Product Name": products,
    "Price": prices,
    "Rating": ratings
})
#* joga o dataframe para um csv
df.to_csv("produtos.csv", index=False, encoding="utf-8")

Here's the screenshot of the code in atom

image

Here's the screenshot of the same code in vscode

image

  • VSCode version: 1.37.1
  • Theme version: 2.1.0

I'm using the python extensions for this, most precisely the MagicPython extension, and it's a python 3.7 code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants