如何将十六进制格式的拉丁字母映射到 python 中对应的拉丁字母
How to map latin letters in hex format to its corresponding latin letter in python
我正在尝试从网络中提取数据。很少有拉丁字母以其普通的十六进制格式出现。
例如:
https://www.zomato.com/ncr/café-mrp-connaught-place-new-delhi
这个link会变成
https://www.zomato.com/ncr/caf%C3%A9-mrp-connaught-place-new-delhi
如何从中取回拉丁字母。我想对此进行概括,并对我的数据框中发生更改的所有拉丁字母执行此操作。
i=1
main_page_url = r"https://www.zomato.com/ncr/connaught-place-delhi-restaurants"
chrome_path = r"C:\Users\HPO2KOR\Desktop\chromedriver.exe"
wd = webdriver.Chrome(chrome_path)
wd.get(main_page_url)
while(i<=2):
rests = wd.find_elements_by_xpath('//a[@class="result-title hover_feedback zred bold ln24 fontsize0 "]')
for rest in rests:
df = df.append({'Rest Name' : rest.text,
'URL' : rest.get_attribute("href")}, ignore_index=True)
nxt_pg = wd.find_element_by_xpath('//a[@class="paginator_item next item"]')
nxt_pg.click()
wd.switch_to_window(wd.window_handles[0])
i+=1
wd.close()
您可以使用urllib.parse.unquote(s)/urllib.parse.quote(s)
这是我的代码条:
>>> urllib.parse.unquote("https://www.zomato.com/ncr/caf%C3%A9-mrp-connaught-place-new-delhi")
'https://www.zomato.com/ncr/café-mrp-connaught-place-new-delhi'
>>> urllib.parse.quote('https://www.zomato.com/ncr/café-mrp-connaught-place-new-delhi')
'https%3A//www.zomato.com/ncr/caf%C3%A9-mrp-connaught-place-new-delhi'
我正在尝试从网络中提取数据。很少有拉丁字母以其普通的十六进制格式出现。
例如:
https://www.zomato.com/ncr/café-mrp-connaught-place-new-delhi
这个link会变成
https://www.zomato.com/ncr/caf%C3%A9-mrp-connaught-place-new-delhi
如何从中取回拉丁字母。我想对此进行概括,并对我的数据框中发生更改的所有拉丁字母执行此操作。
i=1
main_page_url = r"https://www.zomato.com/ncr/connaught-place-delhi-restaurants"
chrome_path = r"C:\Users\HPO2KOR\Desktop\chromedriver.exe"
wd = webdriver.Chrome(chrome_path)
wd.get(main_page_url)
while(i<=2):
rests = wd.find_elements_by_xpath('//a[@class="result-title hover_feedback zred bold ln24 fontsize0 "]')
for rest in rests:
df = df.append({'Rest Name' : rest.text,
'URL' : rest.get_attribute("href")}, ignore_index=True)
nxt_pg = wd.find_element_by_xpath('//a[@class="paginator_item next item"]')
nxt_pg.click()
wd.switch_to_window(wd.window_handles[0])
i+=1
wd.close()
您可以使用urllib.parse.unquote(s)/urllib.parse.quote(s)
这是我的代码条:
>>> urllib.parse.unquote("https://www.zomato.com/ncr/caf%C3%A9-mrp-connaught-place-new-delhi")
'https://www.zomato.com/ncr/café-mrp-connaught-place-new-delhi'
>>> urllib.parse.quote('https://www.zomato.com/ncr/café-mrp-connaught-place-new-delhi')
'https%3A//www.zomato.com/ncr/caf%C3%A9-mrp-connaught-place-new-delhi'