Answer the question
In order to leave comments, you need to log in
" tag using the href attribute?" />
How to get the insides of the "" tag using the href attribute?
I need to get everything inside the tag <a>
using the unique value of the href attribute .
How to implement on BeautifulSoup?
The code:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.tinkoff.ru/invest/stocks/?country=All&orderType=Asc&sortType=ByName&start=0&end=12'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36',
'accept': '*/*'}
def get_HtmlSource(url, params = None):
result = requests.get(url, headers=HEADERS, params=params)
return result
def get_content(source):
soup = BeautifulSoup(source.text, "html.parser")
Stock = soup.find_all('a', href_='/invest/stocks/MMM/')
print(Stock)
Info = []
for item in Stock:
Info.append({'Name': item.find('span', class_="NameColumn__nameWrapper_177eF").get_text()})
Info.append({'Price': item.find('span', class_="Money-module__money_3h4MT").get_text()})
print(Info)
def parse():
source = get_HtmlSource(URL)
if source.status_code == 200:
get_content(source)
else:
print("Request failed")
parse()
Answer the question
In order to leave comments, you need to log in
def get_content(source):
soup = BeautifulSoup(source.text, "html.parser")
Stock = soup.find_all('a', {"href": '/invest/stocks/MMM/'})
Info = []
item = Stock[0]
name = item.find('span', {"class": "NameColumn__nameWrapper_177eF"}).get_text()
Info.append({'Name': name})
item = Stock[2]
price = item.find(("span", {"class": "Money-module__money_3h4MT"})).get_text().split('\xa0')[0]
Info.append({'Price': price})
print(Info)
Stock = soup.find_all('a', href_='/invest/stocks/MMM/')
for row in Stock:
print(row.text)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question