Skip to content

Instantly share code, notes, and snippets.

@ccaglayan
Last active March 29, 2019 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccaglayan/873d2ac2ba5ec2d6d09ed3c8264c971d to your computer and use it in GitHub Desktop.
Save ccaglayan/873d2ac2ba5ec2d6d09ed3c8264c971d to your computer and use it in GitHub Desktop.
import requests
import csv
from bs4 import BeautifulSoup
link = 'https://themeforest.net'
username = input("ThemeForest Username: ")
items = {}
i = 0
for page in range(1,8):
str(page)
r = requests.get(link +'/user/'+username+'/portfolio?page='+page.__str__())
source = BeautifulSoup(r.content,"lxml")
lists = source.find_all('li',attrs={"class":"js-google-analytics__list-event-container"})
for item in lists:
items[i] = {}
items[i]['link'] = link+item.find('a',attrs={"class":"js-google-analytics__list-event-trigger t-link -color-inherit -decoration-reversed"})['href']
items[i]['title'] = item.find('a',attrs={"class":"js-google-analytics__list-event-trigger t-link -color-inherit -decoration-reversed"}).text
items[i]['price'] = item.find('p',attrs={"class":"product-list__price-desktop"}).text
i += 1
with open(username+'_products.csv', mode='w') as csv_file:
fieldnames = ['title', 'link', 'price']
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
for item in items:
writer.writerow(items[item])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment