4

I'm trying to get the text from a website but can't find a way do to it. How do I need to write it?

link="https://www.ynet.co.il/articles/0,7340,L-5553905,00.html"
response = requests.get(link)

soup = BeautifulSoup(response.text,'html.parser')
info = soup.find('div', attrs={'class':'text14'})
name = info.text.strip()
print(name)

This is how it looks: enter image description here

i'm getting none everytime

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Michael
  • 189
  • 1
  • 10

2 Answers2

2
import requests
from bs4 import BeautifulSoup
import json
link="https://www.ynet.co.il/articles/0,7340,L-5553905,00.html" 
response = requests.get(link)
soup = BeautifulSoup(response.text,'html.parser') 
info = soup.findAll('script',attrs={'type':"application/ld+json"})[0].text.strip()
jsonDict = json.loads(info)
print(jsonDict['articleBody'])

The page seems to store all the article data in json in the <script> tag so try this code.

johnsnow06
  • 131
  • 7
  • what about in this case: https://www.ynetnews.com/articles/0,7340,L-5554655,00.html ? any idea how to get the text? it's not working well in my way and not in yours as well – Michael Jul 21 '19 at 11:40
1

The solution is :

info = soup.find('meta', attrs={'property':'og:description'})

It gave me the text i needed

Michael
  • 189
  • 1
  • 10