A
A
Amigun2019-05-29 20:25:12
Python
Amigun, 2019-05-29 20:25:12

How to get the value of a div with a known id that is in other tags in python?

I need to get the value (text) that is in the div tag and with some specific id. But this div is in other "likes".
Under Python

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Yakushenko, 2019-05-29
@Amigun

Install beautifulsoup4 and request .

import requests
from bs4 import BeautifulSoup

html = requests.get(url).text
soup = BeautifulSoup(html, 'html.parser')
find_text = soup.find('div', {'id': 'название нужного id'}).get_text()

V
Vladimir Kuts, 2019-05-29
@fox_12

from lxml import html

tree = html.fromstring('<содержимое какой-то страницы>')

tree.xpath('.//div[@id="<какой-то определенный id>"]')[0].text

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question