[Tutor] Pymongo | Python 3.7 | MongoDb Community : write scrape results to db
Kelvin Zimmerman
zimmerman.k at icloud.com
Fri Dec 13 13:43:20 EST 2019
Hi,
Let me start by saying I am very new to both python and mongo. I am just and hobbyist so my issue maybe basic to most but never less, I am thankful for any help, guidance, as I am stuck!
Objective: Im using to run a craigslist jobs search for multi-locations and then attempt to both print the results to the screen and into the db. I am able to connect to the db without issue, I think my issue is in creating the dict .bson ?? piece to this puzzle.
Please see below:
from craigslist import CraigslistJobs
# database
import pymongo
from pymongo import MongoClient
from unicodedata import name
from _datetime import datetime
from scrapy.utils import url
try:
client = MongoClient()
print("Connected Successfully!")
except:
print("Could Not Connect !")
# dbase client
client = MongoClient()
client = MongoClient('localhost', 27017)
# dbase
db = client['craigslistResults']
# write to database
mydict = {'name': name.get_text(),
'url': url.get_text(),
'datetime': datetime.get_text(),
'price': price.get_text()
}
x = db.craigslistResultsFreelance.insert_many(mydict)
abilene = CraigslistJobs(site='abilene', category='jjj',
filters={'is_telecommuting': True})
for abileneResult in abilene.get_results():
print(abileneResult)
sfbay = CraigslistJobs(site='sfbay', category='jjj',
filters={'is_telecommuting': True})
for sfbayResult in sfbay.get_results():
print(sfbayResult)
newyork = CraigslistJobs(site='newyork', category='jjj',
filters={'is_telecommuting': True})
for newyorkResult in newyork.get_results():
print(newyorkResult)
Any insight is greatly appreciated!
More information about the Tutor
mailing list