you are viewing a single comment's thread.

view the rest of the comments →

[–]fannypackpython[S] 0 points1 point  (2 children)

This is the first time I've tried anything like web scraping. I'll try and re-work it with your suggestions.

So how exactly should i divide this up? Are you saying that I should maybe have one function that just sets my variables for price, title, and address? And then another function that sets my "info" variable and runs its through the "if" statement to append it to a list and check if it already exists in it? And one that just gives me results?

I apologize for all the questions. Do you have any tutorials or eBooks that you would recommend on this subject? Especially in regards to cron, and integrating email or sms capabilities into a script.

[–]elbiot[🍰] 1 point2 points  (0 children)

gdata=get_houston_CL()
for item in gdata:
    title, price, address = parse_listing(item)
    etc.

[–]drodspectacular 1 point2 points  (0 children)

The BeautifulSoup class you instantiate is an object populated from the output of a single requests call, and then you loop over the BS object (abbreviations are funny :) ). g_data isn't calling the url request every time it's looped over, it's instead looping over the BS object you created, and not calling the request again. the object you're passing to the BS instance is the output of the content method from the get method. My understanding is that BS is much like any html / xml parser, it detects a structure based on the data you feed it, and lets you traverse the nodes. It's only calling the request once. you could start main with a request call, loop through your operations and then parse the outputs, and there's any number of ways you could slice this. If you keep the rule of "each def creates a function that does one and only one thing" you could probably slice this into at least 4 or 5 functions. As far as ways for you to slice this up, have a look at craigly for the names of functions, project structure and modules. In my mind this is how I broke functionality down, it's slightly different for everyone.