如何检查某个标签是否在内容中,如果是,则不要访问网站

时间:2017-07-04 21:56:11

标签: python beautifulsoup bs4

所以我想要做的是根据用户的输入访问网站。如果该用户输入的值不返回任何结果,则浏览器不应该打开。这是我目前的代码。

import requests
from bs4 import BeautifulSoup
import webbrowser

jobsearch = input("What type of job?: ")
location = input("What is your location: ")
url = ("https://ca.indeed.com/jobs?q=" + jobsearch + "&l=" + location)

newurl = url
r = requests.get(newurl)
rcontent = r.content
prettify = BeautifulSoup(rcontent, "html.parser")

def site():

  rcontent = r.content
  no_result = prettify.find("div.no_results")
  if no_result == True:
     pass
     print("nothing")
  else:
     website = webbrowser.open_new(newurl);
     return website

site()

0 个答案:

没有答案