简体   繁体   English

在Python中将已解码(来自北印度语)参数添加到给定的url

[英]Add decoded(from Hindi) params to a given url in python

I have this url = ' http://www.bhaskar.com/uttar_pradesh/lucknow/= '. 我有这个网址=' http://www.bhaskar.com/uttar_pradesh/lucknow/= '。 after the "=" sign one Hindi word which denotes the word searched for is given. 在“ =”符号之后,给出了一个北印度语单词,该单词表示要搜索的单词。 I want to be able to add that as a parameter to this url, so that I will only need to change the word each time and not the whole url. 我希望能够将其作为参数添加到此url中,这样我就只需要每次更改单词,而不必更改整个url。 I tried to use this: 我试图用这个:

>>> url = 'http://www.bhaskar.com/uttar_pradesh/lucknow/='
>>> word = 'word1'
>>> conj = url + word

but this gives me the Hindi word in unicode. 但这给了我Unicode中的北印度语单词。 like this: 像这样:

>>> conj
'http://www.bhaskar.com/uttar_pradesh/lucknow/=\xe0\xa6\xb8\xe0\xa6\xb0'

Can anyone help? 有人可以帮忙吗?

but this gives me the Bengali word in unicode 但这给了我Unicode中的孟加拉语单词

No, it does not :) 不,不是的 :)

When you type temp in the terminal, it displays an unique interpretation of the string. 在终端中键入temp时,它将显示字符串的唯一解释。 When you type print(temp) , however, you are getting a more user-friendly representation of the same string. 但是,当您输入print(temp)时,您将获得对同一字符串更友好的表示形式。 In the end, however, the string pointed by temp is the same all the time, it is only presented in different ways. 但是最后, temp指向的字符串一直都是相同的,只是以不同的方式显示。 See, for example, if you get the second one and put it in a variable and print it: 例如,请参见是否获得了第二个并将其放入变量并打印:

>>> temp2 = 'http://www.cfilt.iitb.ac.in/indowordnet/first?langno=3&queryword=\xe0\xa6\xb8\xe0\xa6\xb0'
>>> print(temp2)
http://www.cfilt.iitb.ac.in/indowordnet/first?langno=3&queryword=সর

Actually, you can create the string by using escaped values in all characters, not only the Bengali one: 实际上,您可以通过在所有字符中使用转义值来创建字符串,而不仅仅是孟加拉语:

>>> temp3 = '\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x63\x66\x69\x6c\x74\x2e\x69\x69\x74\x62\x2e\x61\x63\x2e\x69\x6e\x2f\x69\x6e\x64\x6f\x77\x6f\x72\x64\x6e\x65\x74\x2f\x66\x69\x72\x73\x74\x3f\x6c\x61\x6e\x67\x6e\x6f\x3d\x33\x26\x71\x75\x65\x72\x79\x77\x6f\x72\x64\x3d\xe0\xa6\xb8\xe0\xa6\xb0'
>>> print(temp3)
http://www.cfilt.iitb.ac.in/indowordnet/first?langno=3&queryword=সর

In the end, all these strings are the same: 最后,所有这些字符串都是相同的:

>>> temp == temp2
True
>>> temp == temp3
True

So, don't worry, you have the correct string in the variable. 因此,不用担心,变量中包含正确的字符串。 You are only getting a problem if the escaped string is displayed elsewhere. 如果转义的字符串显示在其他位置,您只会遇到问题。 Finish your program, run it until the end and you'll see there will be no errors. 完成您的程序,运行它直到最后,您将看到没有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM