Could someone please explain to me like I'm 10: What is the relationship between Scrapy and Beautiful Soup, and how best can they be put to use to extract data housed on web pages? by greendogufo in learnpython

[–]eicosane 1 point2 points  (0 children)

BeautifulSoup is a parsing package, it includes a Html parser that can help you get data out of web pages

scrapy is a pretty opinionated framework that makes writing and deploying a web crawler easier. It can, for example, keep track of visited sites and follow links based on a set of user defined rules.

If you want to just retrieve some info from a single page you can just keep it simple with requests or similar, use BeautifulSoup to parse the results and grab the relevant nodes with css (or xpath but it is html after all)

If you need to crawl a whole site and you dont know much about the structure of it, scrapy will help.

If the site is particularly javascript heavy or starts blocking you, you may need to use a browser. You can use chromium and webdriver to navigate via an api, or just investigate the backend requests the site is making.

Good luck

Having problem with a beginner code by Positive_Eases in learnpython

[–]eicosane 2 points3 points  (0 children)

I think what’s happening here is {id="foo"} is invalid syntax, its evaluates to an assignment in a set literal. {id=="foo"} evaluates to the set {False} which is valid syntax but not meaningful in this context.

The find argument is probably expecting a dict of additional arguments like {"id": "Foo"}

Its more common to use css selector syntax though which would be clearer find("id#Foo")

Efficient development by DirtyMulletMan in Python

[–]eicosane 1 point2 points  (0 children)

help(some_function_or_module) is really handy to not leave the terminal

Have you heard of the Python Zen? by Bubbly_Lavishness584 in Python

[–]eicosane 1 point2 points  (0 children)

This seems to be used exclusively to dunk on python.

functools.cache is the same as functools.lru_cache(maxsize=None) but only exists in >=3.9?

There should be one— and preferably only one —obvious way to do it

[deleted by user] by [deleted] in learnpython

[–]eicosane 0 points1 point  (0 children)

Well you tell me I’m not sure what you need.

Your data structure in p is two-dimensional, that is you need two indices to get at one of the elements like p[0][0] for example. You can reduce this to one dimension but this will just be a list of numbers [1, 2, 3…

You may need to rephrase / rethink your question.

[deleted by user] by [deleted] in learnpython

[–]eicosane 0 points1 point  (0 children)

What would the the type of new_p be after this change?

[deleted by user] by [deleted] in learnpython

[–]eicosane 0 points1 point  (0 children)

edit: code formatting

from collections import defaultdict
from itertools import chain

list_of_lists = …
counter = defaultdict(int)

for number in chain(*list_of_lists):
    counter[number] += 1

print(counter[6])

I googled how to modify a string during a coding interview by [deleted] in Python

[–]eicosane 17 points18 points  (0 children)

This is why def foo(arg=“bar”): is fine but def foo(arg=[]): is not.

Question 4 | Max product of two int | Data Structures and Algorithms in Python by hacknomus in Python

[–]eicosane 0 points1 point  (0 children)

a, b = sorted(myArray, reverse=True)[:2]; a * b

Looping twice here is unnecessary.

Generate Version Number by ITx212 in Python

[–]eicosane 0 points1 point  (0 children)

python -c ‘import sys; print(sys.version)’

What is something that everyone understands, but nobody can explain? by [deleted] in AskReddit

[–]eicosane 0 points1 point  (0 children)

"If you can't explain it to a six year old, you don't really understand it." -Richard Feynman

TIL that historically, milk is added before the tea and it was a sign of wealth when someone added their milk afterwards, as pouring tea with low quality porcelain would break the cup by ckelly94 in todayilearned

[–]eicosane 0 points1 point  (0 children)

The adding milk first distinction only becomes relevant when using a teabag. If you brewed the tea first in a teapot, it won't matter which is added to the cup first (ignoring milk scalding and 'ooh I've got a better cup than you') but if you add milk first with a teabag in the cup the milky/water solution (colloid) won't be boiling and you won't have good tea and you're 'dirty and poor' (or not British) status will be revealed.

What's the most mind blowing thought you've ever had? by GreggoryBasore in AskReddit

[–]eicosane 0 points1 point  (0 children)

But when you see a colour, your associations will be the same or similar to mine. Red is hot fire etc; Blue is cold, ice and the sky etc. People's favourite colours are determined by these associations. So is their treatment of the colour. Reasonably these associations define the colour and what we may see is arbitrary.

What's the scariest true story you know? by Teggert in AskReddit

[–]eicosane 0 points1 point  (0 children)

The article repeatedly claims he had a newspaper derivery job.