我在URL解析过程中遇到错误。任何建议

时间:2015-08-26 23:02:57

标签: python django

我想创建一个django应用程序,通过输入任何网站的URL,它将返回该网站的图像。

'module'对象没有属性'parse'

这是我的错误。

这是我的应用程序的views.py

from django.shortcuts import render, render_to_response, RequestContext
from django.http import HttpResponse
from django.template import RequestContext, loader
from lxml import html
import requests
import urllib3
import urlparse3

def home(request):
template = loader.get_template('home.html')
c = {}
h = {}
z = []
if request.POST:
url = request.POST["url"]
r = requests.get(url)
tree = html.fromstring(r.text)
c = tree.xpath('//img/@src')
h = tree.xpath('//a/@href')
for x in c:
    if bool(urllib3.parse.urlparse3(x).netloc):
        z.append(x)
    else:
        z.append(str(url) + str(x))

 return render_to_response("home.html", {'h': h, 'z' : z},   context_instance=RequestContext(request))

但是当我输入用于获取图像的URL时,它会返回错误。

1 个答案:

答案 0 :(得分:0)

您不应该使用var trimmedArray = [ {"color":"red", "size": "small", "custom": { "inStock": true, "price": 10 } }, {"color":"green", "size": "small", "custom": { "inStock": true, "price": 30 } }, {"color":"red", "size": "large", "custom": { "inStock": true, "price": 20 } } ]; ,如果您仔细阅读文档,则应该致电urlparse3.urlparse3

相关问题