Spina97
Spina97

Reputation: 199

Can't find and process text taken out of an HTML

I'm trying to search in a webpage the "spanish" content but can't get it at all.

This is the code I have so far:

from bs4 import BeautifulSoup
import requests
import re

url = 'http://www.autotaskstatus.net/'
r = requests.get(url)
estado = r.status_code
r = r.content
soup = BeautifulSoup(r, "html.parser")
data = soup.find_all('span', attrs={'class':'name'})[1]
pais = 'Spanish'
data.get_text()
print(data.text)

I have there the "pais" var so it will be replaced by an input so the user can search the country they want. The only data I get with a 1 there is "Limited Release" but if I go with a 0 I can't filter the results at all

I have been searching all over Internet and couldn't find anyone with this same problem so I can't find a solution.

I am using Python 3.6

Edit: since people seemed to find this unclear I'll explain it now What I have on the page is: - just a part

<div data-component-id="fp5s6cp13l47"
     class="component-inner-container status-green "
     data-component-status="operational"
     data-js-hook="">


    <span class="name">
      Concord
      &nbsp;
    </span>

      <span class="tooltip-base tool" title="https://concord.centrastage.net">?</span>
    <span class="component-status">
      Operational
    </span>

So spanish is like "Concord" and what I want to take out is the "Spanish" (and later on the "operational") which will be in a var so it can later be changed for any country there

Upvotes: 1

Views: 50

Answers (1)

drec4s
drec4s

Reputation: 8077

You can get the Spanish server status using this approach:

from bs4 import BeautifulSoup
import requests

URL = 'http://www.autotaskstatus.net/'
with requests.session() as s:
    s.headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0'}
    r = s.get(URL)
    soup = BeautifulSoup(r.content, "html.parser")
    data = soup.find_all('div', attrs={'class':'component-inner-container'})
    pais = 'Spanish'
    print([d.find('span', {'class': 'name'}).text.strip() + ' - ' + d.find('span', {'class': 'component-status'}).text.strip() for d in data if pais in d.text])

Upvotes: 2

Related Questions