[英]How to retrieve data from an hyperlink in an excel file?
我有一些存儲在本地excel文件中的超鏈接。 所有這些都在一欄中。 例如
| A
| ----------------------------------|
| http://vocab.getty.edu/tgn/8699749|
| http://vocab.getty.edu/tgn/8704811|
| http://vocab.getty.edu/tgn/8702341|
| http://vocab.getty.edu/tgn/1063874|
| http://vocab.getty.edu/tgn/1063880|
| http://vocab.getty.edu/tgn/7032551|
|-----------------------------------|
每個鏈接指向一個頁面,我將從中提取與字段xl:prefLabel相關的信息並將結果存儲在列B中
Openpyxl可能是解決方案嗎?
預期的結果應該類似於
| A | B |
| ----------------------------------| ------------------------
| http://vocab.getty.edu/tgn/8699749| tgn_term:1005671253-fr |
| http://vocab.getty.edu/tgn/8704811| tgn_term:1005683546-de |
| http://vocab.getty.edu/tgn/8702341| tgn_term:1005684314 |
| http://vocab.getty.edu/tgn/1063874| tgn_term:64447 |
| http://vocab.getty.edu/tgn/1063880| tgn_term:64453 |
| http://vocab.getty.edu/tgn/7032551| tgn_term:1001213640 |
|-----------------------------------|------------------------|
快速解決方案是使用Pandas切片:
import pandas as pd
import urllib.request
all_hyperlinks = pd.read_excel(path_to_excel_file, index_col=None, header=None)
first_hl = all_hyperlinks.loc[0, 0] # Get the first hype link
contents = request.urlopen(first_hl).read()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.