Socialabel

Monday, October 21, 2013

[Solved] TypeError: expected string or buffer

Python Craw Engine
 import requests  
 from bs4 import BeautifulSoup  
 query = "Kata Kunci"  
 url = "http://www.google.com/search?q=%s"  
 respon = requests.get(url % query)  
 soup = BeautifulSoup(respon)  

Compile Error!!
  bla bal bal bal bal bal bal .....................
  File "/usr/lib/python2.7/site-packages/bs4/dammit.py", line 203, in __init__  
   self._detectEncoding(markup, is_html)  
  File "/usr/lib/python2.7/site-packages/bs4/dammit.py", line 373, in _detectEncoding  
   xml_encoding_match = xml_encoding_re.match(xml_data)  
 TypeError: expected string or buffer  

Ganti menjadi
 import requests  
 from bs4 import BeautifulSoup  
 query = "Kata Kunci"  
 url = "http://www.google.com/search?q=%s"  
 respon = requests.get(url % query)  
 soup = BeautifulSoup(respon.content)  #  BeautifulSoup(respon.text)

 print soup

Keyword: SEO, Search Engine, Python, Expected String or buffer

1 comment:

  1. thank you for the information provided, we are waiting for the next info

    ReplyDelete