I want to get data located(name, city and address) in div
tag from a HTML file like this:
<div class="mainInfoWrapper">
<h4 itemprop="name">name</h4>
<div>
<a href="/Wiki/Province/Tehran"></a>
city
<a href="/Wiki/City/Tehran"></a>
Address
</div>
</div>
I don't know how can I get data that i want in that specific tag.
obviously I'm using python with beautifulsoup
library.
There are several
<h4>
tags in the source HTML, but only one<h4>
with theitemprop="name"
attribute, so you can search for that first. Then access the remaining values from there. Note that the following HTML is correctly reproduced from the source page, whereas the HTML in the question was not:When run for the URL that you provided
I'm not sure that the printed output is correct on my terminal, however, this code should produce the correct text for a properly configured terminal.