Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extractig an score is not there
#1
Hello.
First of all, thank you in advance anyone who tries to help. I realise this will be not the smartest question ever, but need help as I have no idea about howto begin with this.
I am trying to know which is the score given to a telephone in this web
example, this...
https://www.tellows.es/num/+12345678
In this case is 8, but cannot find where and how to scrap
regards
Reply
#2
How it works is that you should give it try,to show some effort
Look at this for some basic way to do web-scraping in Python.

So the start could be like this.
import requests
from bs4 import BeautifulSoup

number = '+12345678'
url = f'https://www.tellows.es/num/{number}'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
print(soup.find('title').text)
Now look at page source the Score number is in the img tag,and it's a attributes of the img tag.
In BS can get attributes bye using attrs.
Reply
#3
I have been able to "isolate" this printing a certain class name (scorepic) doing this:

div=soup.findAll("div", {"class": "scorepic"})
print(div)
the output of printing div is this

[<div class="scorepic">
<a href="https://blog.tellows.es/como-funciona-el-puntaje-de-tellows/" style="line-height:0em;" target="_blank">
<img alt="tellows Evaluaci▒n para xxxxxxxx : Score 5" class="scoreimage" height="108" src="/images/score/s5.jpg" style="width: 100px;" width="100">
</img></a>
</div>]

I would like to extract the value of score as a number....
Could yoy help me?
Reply
#4
Use Code Tag
(Apr-09-2022, 10:12 PM)jrotaetxe Wrote: I would like to extract the value of score as a number....
import requests
from bs4 import BeautifulSoup

number = '+12345678'
url = f'https://www.tellows.es/num/{number}'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
score = soup.select_one('#tellowsscore > div > a > img')
score_nr = score.attrs['alt'].split(':')[-1].strip()
score_int = int(score_nr.split()[1])
print(score_nr)
print(score_int)
Output:
Score 8 8
Reply
#5
Thank you, thank you.
This let me procced with some modifications in a very interesting piece of software for raspberry pi:
Call Attendant, by Bruce Schubert
Any interested, look for callattendant in Github. Is a antispam bot for fixed lines....
Thank you again
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020