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
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
I Am InEvitable

Reply

RE: Bs4 to List/Dictionary Question #3
(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 #4
(08-07-2020, 10:46 PM)mudrig Wrote:
(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
Happy coding
I Am InEvitable

Reply






Users browsing this thread: 1 Guest(s)