Login Register


Bs4 to List/Dictionary Question filter_list
Author
Message
Bs4 to List/Dictionary Question #1
This is my current code:

Code:
from bs4 import BeautifulSoup import requests # Search Parameter q='' # Url to Search for questions QUERY_URL = "url will be here" + q req = requests.get(QUERY_URL) soup = BeautifulSoup(req.text, "html.parser") # Find all link tags question-hyperlink classes with a limit of 15 questions = soup.find_all("a", class_="question-hyperlink" , limit=15) # Remove html tags and only print the text for a in questions: print(a.text)

Everything prints out correctly in the output as I need but I want to be able to pull one at a time from it instead of all 15 at once. So how can I change
Code:
print(a.text)
to output a dictionary or list instead .. thanks
“I am thankful for all of those who said NO to me. It’s because of them I’m doing it myself.” – Albert Einstein

Reply

RE: Bs4 to List/Dictionary Question #2
(08-07-2020, 11:18 AM)sefefew Wrote: Declare a list,

some_list = []

And inside for loop,

some_list.append(a.text)

Or

Declare a dict,
some_dict = {}

And inside for loop,
some_dict[some_key value] = a.text

Exactly what I was looking for thanks
“I am thankful for all of those who said NO to me. It’s because of them I’m doing it myself.” – Albert Einstein

Reply

RE: Bs4 to List/Dictionary Question #3
It is not easier to buy a dictionary with the language you need, that is, it already depends on the purpose of each one. For example, I wanted to learn as many [link redacted] as possible, and I bought a dictionary from Amazon with the specifics of the terms. You can also find dictionaries with grammar or phrases. But what is the purpose of this whole thing? I can't understand, so could you please explain to me, because I find the scheme quite interesting. It wouldn't hurt to delve deeper into other areas, but it's personal development.
(This post was last modified: 09-06-2021, 10:25 PM by Ciceniss.)

Reply







Users browsing this thread: 1 Guest(s)