Skip to content
Advertisements

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                 = 'https://www.meetup.com/find/events/tech/?allMeetups=false&radius=31&userFreeform=New+York%2C+New+York%2C+USA&mcId=c10001&change=yes&eventFilter=mysugg'

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

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

browser.close()
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: