N
N
NOblo2020-07-27 12:07:28
Python
NOblo, 2020-07-27 12:07:28

How to get data from html code in python?

From this:

<html>
  <head>
    <title>Hello, from tc.inq.com</title>
  </head>
  <body bgcolor=white>

    <p>This is the home page for the inq.com. </p>

  </body>
</html


Get this is what is in <\p>
To get it like this: How to track by tag? Is there a tool, or do I need to use find?
var = "This is the home page for the inq.com."

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SKEPTIC, 2020-07-27
@NOblo

pip install lxml

import lxml.html as lxml

request = requests.get('https://yandex.ru').content
doc = lxml.document_fromstring(request)
p = doc.xpath("//p")[0].text

V
Vadim Shatalov, 2020-07-27
@netpastor

https://pythonhosted.org/pyquery/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question