python 3.x - find_all() returns None -


i'm trying dollar's value in google web page using beautiful soup. however, every call find_all() function returns none. don't know have do. me, please!

code:

#get dollar value    requests import *     bs4 import *     r = get("https://www.google.com.br/#q=dolar")  if (r.status_code != 200):   print ("conexão inválida") else:   print("prosseguindo...")    soup = beautifulsoup(r.content, "html.parser")    print (soup.find_all("div", attrs = {"class" : "vk_ans vk_bk"}))   print (soup.find_all("div", class_="vk_ans vk_bk"))   print (soup.find_all(string="reais"))   print (soup.find_all(class_="vk_ans"))   print (soup.select("div.vk_ans.vk_bk"))   print (soup.html.find_all("div", class_="vk_ans"))   print (soup.select(".vk_ans vk_bk")) 

i'm using python 3.4 , bs4.4.0 windows 8.1

find_all returning none because it's not finding elements you're requesting. take account html code see in browser @ https://www.google.com.br/#q=dolar may not same code that requests.get fetching.

you can check searching classnames in string of response:

in [13]: "vk_ans" in r.content out[13]: false 

there's no trace of string vk_ans in code.

also, 2 notes:

  • using google fetch current value of dollar not idea. try using other website not change google's homepage.
  • do not use from x import *. you're poluting global namespace of script.

Comments