ran_hao
Small_Ran
2017-11-30 07:41

python问题:TypeError: expected string or buffer

  • python
  • 数据
 import requests
import re
#这是用requests进行的数据爬取
url = 'https://car.autohome.com.cn/photo/series/26709/1/3793691.html'
html = requests.get(url)
# print (html.text)

img_url = re.findall(r'<img id="img" src="(.*?)"',html)[0]
img_url = 'http:' + img_url
print(img_url)
img_response = requests.get(img_url)
img_data = img_response.content
f = open('2.jpg','wb')
f.write(img_data)
f.close()
报错:
Traceback (most recent call last):
  File "D:/Java/Python/src/hao/__init__.py", line 9, in <module>
    img_url = re.findall(r'<img id="img" src="(.*?)"',html)[0]
  File "C:\Python27\lib\re.py", line 181, in findall
    return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答