django HTTP错误400:错误的请求

时间:2016-02-28 15:34:04

标签: python django beautifulsoup urllib

我想在我加载页面时,def celphone工作并从网址获取span标记的内容并将其打印在页面上,但它会返回错误。

views.py:

from django.http import *
from django.shortcuts import render
from django.http import HttpResponseRedirect
import pymysql



def cellphone(request):
    from bs4 import BeautifulSoup
    from urllib.request import urlopen

    url ='http://www.digikala.com/Product/DKP-95906/Huawei-Mate-S-Dual-SIM-64GB-Mobile-Phone/%DA%AF%D9%88%D8%B4%D9%8A-%D9%85%D9%88%D8$'
    data = urlopen(url)
    soup = BeautifulSoup(data, 'html.parser')
    price =  soup.body.find('span', attrs={'id':'frmLblPayablePriceAmount'}).text
    return render(request, 'system.html', {'price': price})

这引发了这个错误:

Exception Type:     HTTPError
Exception Value:    HTTP Error 400: Bad Request

糟糕的请求是什么意思?

0 个答案:

没有答案