Skip to content

Create JSON File With Python Selenium

I had to pull data from the Internet for a project. The easiest way to do this is to use python selenium.

from selenium import webdriver     
import random
import time                        
import json

browser             = webdriver.Firefox()      
count               = 1
data                = {}
data['cards_title'] = []

url                 = ''

while count <= 5:
    title = browser.find_element_by_xpath('//*[@id="simple-view"]/div[1]/ul/li[2]/ul/li['+ str(count) +']/div[2]/div/a/span').text
    count += 1

with open('data.json', 'w') as outfile:
    json.dump(data, outfile)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: