unexpected-token 相关问题


动态获取父节点及其值

我有一个xml,我可以在其中获取节点中节点的名称,例如值、宽度、高度、重量... 例子: 我有一个 xml,可以在其中获取节点中节点的名称,例如值、宽度、高度、重量…… 示例: <?xml version="1.0" encoding="utf-8"?> <Data totalExecutionTime="00:00:00.0076034" totalCount="1">   <Features>     <ProductID id="100" language="NLB" caption="Product ID" captionAlternative="Product ID" unit="" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="" viewGroup="" viewGroupOrder="0" topViewGroupId="b65b432a-1bf1-4fd4-ae92-03418d3204be" topViewGroup="Algemeen" topViewGroupOrder="1" viewOrder="0" form="Complex" dataType="String" readOnly="False" />     <Length id="245" language="NLB" caption="Lengte" captionAlternative="Lengte" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="1" form="Simple" dataType="Number" readOnly="False" />     <Width id="242" language="NLB" caption="Breedte" captionAlternative="Breedte" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="2" form="Simple" dataType="Number" readOnly="False" />     <Height id="244" language="NLB" caption="Hoogte" captionAlternative="Hoogte" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="3" form="Simple" dataType="Number" readOnly="False" />     <Depth id="771" language="NLB" caption="Diepte" captionAlternative="Diepte" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="4" form="Simple" dataType="Number" readOnly="False" />     <Weight id="243" language="NLB" caption="Gewicht" captionAlternative="Gewicht" unit="kg" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="28813941-54b4-4511-b91e-d9ae53aa03e9" viewGroup="Afmetingen en gewicht" viewGroupOrder="91" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="5" form="Simple" dataType="Number" readOnly="False" />     <LoadCapacity id="457" language="NLB" caption="Draagvermogen" captionAlternative="Draagvermogen" unit="kg" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="c9d7dd7e-8a85-47cc-8542-2695e4615f75" viewGroup="Technische specificaties" viewGroupOrder="15" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="6" form="Simple" dataType="Number" readOnly="False" />     <Volume id="435" language="NLB" caption="Inhoud" captionAlternative="Inhoud" unit="l" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="bfaf678b-8b9d-4cea-aa99-08edd8316dc7" viewGroup="Algemene specificaties" viewGroupOrder="13" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="7" form="Simple" dataType="Number" readOnly="False" />     <TireSize id="705" language="NLB" caption="Banden maat" captionAlternative="Banden maat" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="c9d7dd7e-8a85-47cc-8542-2695e4615f75" viewGroup="Technische specificaties" viewGroupOrder="15" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="8" form="Simple" dataType="String" readOnly="False" />     <LoadingScoop id="706" language="NLB" caption="Laadschep" captionAlternative="Laadschep" unit="mm" help="" abbr="" groupId="73660834-eea8-4d67-8e84-b38e2742706a" group="Alles" groupOrder="0" viewGroupId="c9d7dd7e-8a85-47cc-8542-2695e4615f75" viewGroup="Technische specificaties" viewGroupOrder="15" topViewGroupId="590c0ee7-e1eb-4e18-b583-eba8984ffe82" topViewGroup="Specificaties" topViewGroupOrder="4" viewOrder="9" form="Simple" dataType="String" readOnly="False" />   </Features>   <ProductID id="25137" parentId="0" brand="Normal" order="0" createdDate="2020-03-24T15:30:07.21" modifiedDate="2023-11-20T20:01:33.87">     <Value seq="0" modifiedDate="2020-03-24T15:30:10.493">111TA5851</Value>     <Width seq="0" modifiedDate="2020-03-24T15:30:10.493">515</Width>     <Height seq="0" modifiedDate="2020-03-24T15:30:10.493">1100</Height>     <Weight seq="0" modifiedDate="2020-04-02T13:18:09.44">7.7</Weight>     <LoadCapacity seq="0" modifiedDate="2020-03-24T15:30:10.493">150</LoadCapacity>     <LoadingScoop seq="0" modifiedDate="2020-03-24T15:30:10.493">350x170</LoadingScoop>   </ProductID> </Data> 我想要的是动态获取对应父节点的hte值。我可以获得如下节点名称: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <table> <xsl:for-each select="/Data/ProductID/*"> <xsl:variable name="myVariable" select="name(.)"/> <xsl:variable name="HasValue" select="count(/Data/ProductID/*)" /> <tr> <td><xsl:value-of select="name(.)" /></td> <td><xsl:value-of select="local-name()" /></td> <td><xsl:value-of select="name()" /></td> <td><xsl:value-of select="/Data/node($myVariable)/@unit" /></td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet> 但是我不知道如何获取相应的父节点及其值,例如单位元素。 我已经尝试过<xsl:value-of select="/Data/$myVariable/@unit" /></td>,但不起作用。我会不断收到错误:Unexpected token '$myVariable' during parsing of '<AnyKindTest>'。 我想你想声明一把钥匙 <xsl:key name="element-key" match="Data/Features" use="name()"/> 然后你想使用例如key('element-key', name())/@unit。 你写道: <xsl:value-of select="/Data/$myVariable/@unit" /> 我认为你的问题可能是重复的 使用 2 个参数进行 xslt 测试 您正在尝试使用 $myVariable,就好像它所保存的字符串可以以文本方式替换到您的 XPath 表达式中一样。您可能想要的是 /Data/*[name()=$myVariable]/@unit 很多人都犯过这个错误,但我不知道为什么。我不认为人们会将变量 $op 设置为“+”或“-”,然后期望 @x $op @y 执行适当的加法或减法。除非他们以前的编程经验完全是用宏语言。


获取请求标头丢失(x-auth-token)以及如何返回流格式PDF?

我正在开发一个 POST API,它调用服务来返回 .pdf 文件的 url。 它返回{url、token 和其他字段}。我想重定向到这个网址并获取 pdf 文件,但失败了。 例子...


需要什么才能使图请求成功?

在 GET 请求上: https://graph.microsoft.com/v1.0/users/me/joinedTeams 从以下位置检索 accesstoken:https://login.microsoftonline.com/4c3a1b30-xxxx-xxxx-9581-0281c4427992/oauth2/token 我是


当多个API的Access token同时失效时,如何刷新并行调用的多个API的Access token?

在我的 React Native 应用程序中,我在登录后获得访问令牌和刷新令牌。 有一个常用函数,当访问令牌无效时,使用刷新令牌再次调用访问令牌...


发送 csv 时“(400) 输入错误。某些域无效”

H。我需要通过ajax发送csv文件。我写了这段代码 $('#send-csv').click(function(){ var CSRF_TOKEN = document.querySelector('meta[name="csrf-token"]').getAttribute("c...


当 cy.wait() 超时时我该如何做?

此代码等待响应并在响应到达后执行操作。 等待超时时我该如何做? cy.wait('@login').then((拦截) => { const token = 拦截.响应...


登录使用 OAuth 2.0 协议的 MercadoLibre API 时如何解决“code_verifier 是必需参数”错误

我有 Mercado Libre API 的 Auth python 代码: url = 'https://api.mercadolibre.com/oauth/token' 有效负载 = {'grant_type': '授权代码', 'client_id':app_id, '


更新到.net 8 会破坏 Bearer Token 授权

我的实现工作正常,直到更新到 .net 8。 现在我只收到 401。 已尝试所有相关SO问题的答案,但无济于事


避免重写内存中相同位置的解决方案?

无效扫描(扫描仪*扫描仪){ // 初始化扫描器 int length_of_src = strlen(扫描仪->源); 扫描仪->令牌 = malloc(sizeof(Token) * length_of_src + 1); int *行 = ...


尝试访问 API 时不断出现 401 未经授权

我很确定我的ID和秘密是正确的。 这是真正的链接:(https://sandbox.mngkargo.com.tr/en/node/266) 发布 https://testapi.mngkargo.com.tr/mngapi/api/token 标题: 内容-


我可以将复杂的对象传递给命令处理程序和事件处理程序 AXON Spring boot

我的java版本17和axon 4.5.3 这是我的控制器。 buildOrder = orderService.buildOrder(orderDto.getCartCode(),token); 创建订单命令 ...


PHP 空会话值的未定义数组键

我在 WordPress 上有一个自定义插件,可以获取 url 参数值(示例:test.com/?token=hello)并将其发送到 Salesforce 字段。 升级到 PHP8.0 后,我收到有关


Symfony 6.0 - 在控制器中强制注销用户

我如何强制注销从新 Symfony 6 上的 controle 登录的用户? (6.0.1版本) 我尝试了 $tokenStorage->setToken($token);但 setToken() 需要 2 个参数: (公共函数 setToken(string $tok...


Spotify API {'error': 'invalid_client'} 授权代码流程 [400]

这是我向 https://accounts.spotify.com/api/token 发出 POST 请求的多次尝试之一。 范围设置为“播放列表修改公共、播放列表修改私有”。 我正在使用 Python 3.7,Djan...


是否可以在 Next.JS 中使用路径段作为 API 路由?

我使用 Next.js v.14 的应用程序路由器并具有以下目录结构: /app/api/github/webhook/[令牌]/route.ts 如何获取 POST 请求处理程序中的 [token] 值?有吗


将 twig 转换为 tpl

我尝试将twig转换为tpl,以便能够在2,3,0中使用3,0,0付款扩展。 树枝线 我尝试将 twig 转换为 tpl 以便能够在 2,3,0 中使用 3,0,0 付款扩展。 树枝线 <select name="payment_special_mode" class="form-control"> <option value="1" {{ payment_special_mode? 'selected' : '' }}>{{ text_enabled }}</option> <option value="0" {{ payment_special_mode? '' : 'selected' }}>{{ text_disabled }}</option> </select> <select name="payment_special_mode" class="form-control"> <option value="1" {{ payment_special_mode? 'selected' : '' }}>{{ text_enabled }}</option> <option value="0" {{ payment_special_mode? '' : 'selected' }}>{{ text_disabled }}</option> </select> 前往tpl线路 <select name="payment_special_mode" class="form-control"> <?php if ($payment_special_mode) { ?> <option value="1" selected="selected"><?php echo $text_enabled; ?> </option> <option value="0"><?php echo $text_disabled; ?></option> <?php } else { ?> <option value="1"><?php echo $text_enabled; ?></option> <option value="0" selected="selected"><?php echo $text_disabled; ?></option> <?php } ?> </select> 这是正确的吗 是的,我做到了,但没有成功,仍然在管理扩展行中可见,但有文本。用了opencartbot转换器,转换了大部分,但是有4行没有。检查了所有文件和文件夹。 读了很多标题,问了很多论坛,我找不到办法。如果我能以正确的方式将 twig 转换为 tpl,则在 3,0,2 扩展中必须有效。 我还将 user_token 更改为 token,$data['token'] = $this->session->data['token']


通过更少的 Java API 调用来映射 Google 云端硬盘内容的有效方法

大家好,我有一个代码,用于列出共享驱动器中存在的文件(以便稍后下载并创建相同的文件夹路径) 目前我做这样的事情: 哈希映射 大家好,我有一个代码,用于列出共享驱动器中存在的文件(以便稍后下载并创建相同的文件夹路径) 目前我正在做这样的事情: HashMap<String, Strin> foldersPathToID = new HashMap<>(); //searching all folders first saving their IDs searchAllFoldersRecursive(folderName.trim(), driveId, foldersPathToID); //then listing files in all folders HashMap<String, List<File>> pathFile = new HashMap<>(); for (Entry<String, String> pathFolder : foldersPathToID.entrySet()) { List<File> result = search(Type.FILE, pathFolder.getValue()); if (result.size() > 0) { String targetPathFolder = pathFolder.getKey().trim(); pathFile.putIfAbsent(targetPathFolder, new ArrayList<>()); for (File file : result) { pathFile.get(targetPathFolder).add(file); } } } 递归方法在哪里: private static void searchAllFoldersRecursive(String nameFold, String id, HashMap<String, String> map) throws IOException, RefreshTokenException { map.putIfAbsent(nameFold, id); List<File> result; result = search(Type.FOLDER, id); // dig deeper if (result.size() > 0) { for (File folder : result) { searchAllFoldersRecursive(nameFold + java.io.File.separator + normalizeName(folder.getName()), folder.getId(), map); } } } 搜索功能是: private static List<com.google.api.services.drive.model.File> search(Type type, String folderId) throws IOException, RefreshTokenException { String nextPageToken = "go"; List<File> driveFolders = new ArrayList<>(); com.google.api.services.drive.Drive.Files.List request = service.files() .list() .setQ("'" + folderId + "' in parents and mimeType" + (type == Type.FOLDER ? "=" : "!=") + "'application/vnd.google-apps.folder' and trashed = false") .setPageSize(100).setFields("nextPageToken, files(id, name)"); while (nextPageToken != null && nextPageToken.length() > 0) { try { FileList result = request.execute(); driveFolders.addAll(result.getFiles()); nextPageToken = result.getNextPageToken(); request.setPageToken(nextPageToken); return driveFolders; } catch (TokenResponseException tokenError) { if (tokenError.getDetails().getError().equalsIgnoreCase("invalid_grant")) { log.err("Token no more valid removing it Please retry"); java.io.File cred = new java.io.File("./tokens/StoredCredential"); if (cred.exists()) { cred.delete(); } throw new RefreshTokenException("Creds invalid will retry re allow for the token"); } log.err("Error while geting response with token for folder id : " + folderId, tokenError); nextPageToken = null; } catch (Exception e) { log.err("Error while reading folder id : " + folderId, e); nextPageToken = null; } } return new ArrayList<>(); } 我确信有一种方法可以通过很少的 api 调用(甚至可能是一个调用?)对每个文件(使用文件夹树路径)进行正确的映射,因为在我的版本中,我花了很多时间进行调用 service.files().list().setQ("'" + folderId+ "' in parents and mimeType" + (type == Type.FOLDER ? "=" : "!=") + "'application/vnd.google-apps.folder' and trashed = false").setPageSize(100).setFields("nextPageToken, files(id, name)"); 每个子文件夹至少一次......并且递归搜索所有内容需要很长时间。最后,映射比下载本身花费的时间更多...... 我搜索了文档,也在此处搜索,但没有找到任何内容来列出具有一个库的所有驱动器调用任何想法? 我想使用专用的 java API 来获取共享 GoogleDrive 中的所有文件及其相对路径,但调用次数尽可能少。 提前感谢您的时间和答复 我建议您使用高效的数据结构和逻辑来构建文件夹树并将文件映射到其路径,如下所示 private static void mapDriveContent(String driveId) throws IOException { // HashMap to store folder ID to path mapping HashMap<String, String> idToPath = new HashMap<>(); // HashMap to store files based on their paths HashMap<String, List<File>> pathToFile = new HashMap<>(); // Fetch all files and folders in the drive List<File> allFiles = fetchAllFiles(driveId); // Build folder path mapping and organize files for (File file : allFiles) { String parentId = (file.getParents() != null && !file.getParents().isEmpty()) ? file.getParents().get(0) : null; String path = buildPath(file, parentId, idToPath); if (file.getMimeType().equals("application/vnd.google-apps.folder")) { idToPath.put(file.getId(), path); } else { pathToFile.computeIfAbsent(path, k -> new ArrayList<>()).add(file); } } // Now, pathToFile contains the mapping of paths to files // Your logic to handle these files goes here } private static List<File> fetchAllFiles(String driveId) throws IOException { // Implement fetching all files and folders here // Make sure to handle pagination if necessary // ... } private static String buildPath(File file, String parentId, HashMap<String, String> idToPath) { // Build the file path based on its parent ID and the idToPath mapping // ... }


Python 3.7 BeautifullSoup soup.find 错误 - find() 不接受关键字参数

我从 URL 获得了以下 HTML: 我从 URL 中获得了以下 HTML: <h4> \r\n \r\n\r\n <a href="/l"> \r\n <!-- mp_trans_rt_start id="1" args="as" 1 -->\r\n <span class="brandWrapTitle">\r\n <span class="productdescriptionbrand">Mxxx</span>\r\n </span>\r\n <span class="nameWrapTitle">\r\n <span class="productdescriptionname">Axxxname</span>\r\n </span>\r\n <!-- mp_trans_rt_end 1 -->\r\n </a> \r\n\r\n </h4> 我正在尝试使用 python 来查找类名: import urllib.request from bs4 import BeautifulSoup url = "https://link" user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36' urlwithagent = urllib.request.Request(url,headers={'User-Agent': user_agent}) response = urllib.request.urlopen(urlwithagent) soup = response.read() product = soup.find("h4", attrs ={"class=": "productdescriptionname"}) print (product) Everythink 完美运行直到上线: product = soup.find("h4", attrs ={"class=": "productdescriptionname"}) 我收到如下错误: find() takes no keyword arguments 我不知道如何解决它 - 有很多信息,但没有任何作用:/ 在使用 BeautifulSoup 之前,您需要将其转换为 find 对象,否则它会使用 str.find 例如: soup = BeautifulSoup(response.read(), "html.parser") product = soup.find("h4", attrs ={"class": "productdescriptionname"}) print (product) 我认为这值得一提,如果 find 方法有问题,检查 type(soup) 是一个很好的方法来查明您是否正在使用正确的 bs4.BeautifulSoup 对象而不是 str。 我想在这里指出一件事,如果使用 soup.prettify() 使 html 可读。需要注意的是,.prettify() 将 bs4.BeautifulSoup 转换为 str。所以这应该单独使用,例如: soup = BeautifulSoup(response) # type(soup) --> bs4.BeautifulSoup print(soup.prettify()) # print readable html 不喜欢: soup = BeautifulSoup(response).prettify() # type(soup) --> str 我在网上读到的关于这个问题的另一件事是这样的:“你的 beautiful soup 版本可能不支持 find。”因此,我最终升级和降级了版本很多次,然后才意识到这是一个错误的陈述由业余爱好者制作。 在打印之前我已经为此奋斗了大约 45 分钟type(soup)。我希望这可以节省其他人的时间。 Может кому подойдет история такая повторял за автором ютуба и переписывал код для парсинга и вышла такая же ошибка как в вопросе искал читал, шерстил инет пока не начал перепроверять свой код в общем мой код с ошибкой: from requests import Session from bs4 import BeautifulSoup as BS from time import sleep headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 YaBrowser/23.11.0.0 Safari/537.36'} work = Session() work.get('https://quotes.toscrape.com/', headers=headers) response = work.get('https://quotes.toscrape.com/login', headers=headers) soup = BS(response.text, 'lxml') token = soup.find('from').find('input').get('') в чем здесь ошибка? вот в этой строке token = soup.find('from').find('input').get('') а именно soup.find('from') я решил скать ошибку методом исключения поэтому довел до такого состояния и понял что в странице нет тэга '来自' а есть тэг '形式' как только поменял на тэг 'form' ошибка с soup.find() - find() ушла может кому поможет


© www.soinside.com 2019 - 2024. All rights reserved.