[Tutor] Pymongo | Python 3.7 | MongoDb Community : write scrape results to db

Richard Damon Richard at Damon-Family.org
Sun Dec 15 19:00:07 EST 2019


On 12/15/19 6:47 PM, Alex Kleider wrote:
> On 2019-12-13 10:43, Kelvin Zimmerman via Tutor wrote:
>> 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.
>
> I don't have many of the non standard library modules that you are
> using so I commented out a lot of stuff just to get to what I believe
> is the first problem:
>
> from _datetime import datetime
> from unicodedata import name
> #import pymongo
> #from craigslist import CraigslistJobs
> #from pymongo import MongoClient
> #from scrapy.utils import url
> # database
> #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()
>           }
>
> and here's the traceback I got:
> python tutor.py
> Traceback (most recent call last):
>   File "tutor.py", line 20, in <module>
>     mydict = {'name': name.get_text(),
> AttributeError: 'builtin_function_or_method' object has no attribute
> 'get_text'
>
> It surprises me that the error reported wasn't
> NameError: name 'name' is not defined
>
>
> I suggest you send the Traceback you are getting to the list.
>

This gets a binding for name:

from unicodedata import name

But that name is a method, and it doesn't have an attribute get_text.

I suspect something else is wanted here.

-- 
Richard Damon



More information about the Tutor mailing list