2

Hi I am trying to write a program that scrapes a URL and if the scrape data contains a particular string do something how can i use beautiful soup to achieve this

import requests
from bs4 import BeautifulSoup
data = requests.get('https://www.google.com',verify=False)
soup= BeautifulSoup(data.string,'html.parser')
for inp in soup.find_all('input'):
    if inp == "Google Search":
        print ("found")
    else:
        print ("nothing")
Rahul
  • 109
  • 1
  • 7

2 Answers2

0

Your inp is a html object. You must use get_text() function

import requests
from bs4 import BeautifulSoup
data = requests.get('https://www.google.com',verify=False)
soup= BeautifulSoup(data.string,'html.parser')
for inp in soup.find_all('input'):
    if inp.get_text() == "Google Search":
        print ("found")
    else:
        print ("nothing")
0

verify = False, disables certificate verification. This is a security matter. Especially if you are inside a company network this is dangerous because it opens the possibility for a man in the middle attack. You should use proper certificate authorization.

MLAlex
  • 142
  • 10