Hello! Faced such a problem: BeautifulSoup seems to work, but displays a void (although the page has the desired element). What am I doing wrong? You need to parse the answer (r.text) and if there is a definite word in the answer, output it to print:

r = requests.get ('http://mysite.com/') status = r.status_code if status == 200: soup = BeautifulSoup(r.text) h3 = soup.find_all('слово что я ищу') print(h3) 

the result of the script is just [], but I would like to see the word you are looking

  • one
    Are you looking for some arbitrary word or html tag? - stxdtm
  • It is a specific word, for example, weather - babyborn

1 answer 1

Based on the documentation , the text attribute must also be used:

 soup.findAll(text="слово что я ищу") 

And at the output you will receive either your value or emptiness.

But I would recommend looking through the regular season:

 soup.findAll(text=re.compile("слово что я ищу")) 
  • before googled, people for some reason did not recommend regulars (speed?) - babyborn
  • one
    Yes, but judging by the conclusion from the examples, if this word is part of a line, then it will output a line, and in the first variant only this word - Yaroslav Molchan
  • soup.findAll (text = "word that i'm looking for") this option also displays [], soup.findAll (text = re.compile ("word that i'm looking for")) this option displays the entire page in json format (answer to request- in json) - babyborn
  • one
    Well, it turns out that he is doing it right, then it’s necessary to give him not the whole page with the Initiative BeautifulSoup but the part in which you do the check and which you would like to output if I correctly understood the task - Yaroslav Molchan
  • one
    @dimahimma Do you need to search for a word throughout the site? Ie if it is there at all, we deduce True ? - Pavel Durmanov