Поскольку вы используете BeautifulSoup, вы можете проанализировать его с помощью xml
. Примерно так:
import requests
from bs4 import BeautifulSoup
endpoint = 'http://data.alexa.com/data'
url = 'insert the value you are using here'
data = dict(
cli=10,
dat=snbamz,
url=url
)
r = requests.get(url, data=data)
soup = BeautifulSoup(r.content, 'xml')
rank = soup.REACH.get('RANK')
Это не полный пример, но я надеюсь, что его можно использовать в качестве отправной точки, откуда вы сможете развиваться оттуда.
Вот подтверждение концепции:
Python 3.7.5 (default, Dec 15 2019, 17:54:26)
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
>>> alexa = '''
... <!--
... Need more Alexa data? Find our APIS here: https://aws.amazon.com/alexa/
... -->
... <ALEXA VER="0.9" URL="google.com/" HOME="0" AID="=" IDN="google.com/">
... <SD TITLE="A" FLAGS="" HOST="google.com">
... <OWNER NAME="aa"/>
... </SD>
... <SD>
... <POPULARITY URL="google.com/" TEXT="1" SOURCE="panel"/>
... <REACH RANK="1"/>
... <RANK DELTA="+0"/>
... <COUNTRY CODE="US" NAME="United States" RANK="1"/>
... </SD>
... </ALEXA>
... '''
>>> soup = BeautifulSoup(alexa, 'xml')
>>> rank = soup.REACH.get('RANK')
>>> rank
'1'
>>>