Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
¿Cómo acceder a 'padres' desde BeautifulSoup usando seleccionar o buscar?
import requests from bs4 import BeautifulSoup # raw = requests.get("https://www.daum.net") # raw = requests.get("http://127.0.0.1:5000/emp") response = requests.get("https://vip.mk.co.kr/newSt/rate/item_all.php?koskok=KOSPI&orderBy=upjong") response.raise_for_status() response.encoding= 'EUC-KR' html = response.text bs = BeautifulSoup(html, 'html.parser') result = bs.select("tr .st2") <tr> <td width='92' class='st2'><a href="javascript:goPrice('000020&MSid=&msPortfolioID=')" title='000020'>somethinbg</a></td> <td width='60' align='right'>15,100</td> <td width='40' align='right'><span class='t_12_blue'>▼300</span></td> </tr>

Quiero obtener datos de alguien usando BeautifulSoup. Pero debería acceder al Nodo principal donde tiene . Sin embargo, es muy difícil hacerlo.

Este es el código:

Entonces, ¿cómo puedo obtener datos del padre que tiene '<tr class ='st2>'?

aquí está el ejemplo

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede acceder al elemento principal en BeautifulSoup a través del atributo parent del elemento. Dado que solicitó una lista de elementos, esto debe hacerse en una iteración.
Supongo aquí que desea extraer cada fila de la tabla.

 import requests from bs4 import BeautifulSoup response = requests.get("https://vip.mk.co.kr/newSt/rate/item_all.php?koskok=KOSPI&orderBy=upjong") response.raise_for_status() response.encoding= 'EUC-KR' html = response.text bs = BeautifulSoup(html, 'html.parser') result = [[child.text for child in elem.parent.findChildren('td', recursive=False)] \ for elem in bs.select('tr .st2')]

El resultado es:

 [ ['동화약품', '15,100', '▼300'], ['유한양행', '61,100', '▼400'], ['유한양행우', '58,900', '▲300'], ... ]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!