Python WOS搜索函数TypeError:应为字符串或类似字节的obj

2024-09-27 02:25:24 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试使用python wos库从科学网进行自动下载。 抛出一个似乎来自wos包的错误,但我不确定

我试过在底层的库中乱搞,但这似乎是一种不好的做法

x='my query'

with WosClient( lite=True) as client:
    client.connect()
    wos.utils.query(client, str(x))


Authenticated (SID: 6CZsG4iKOFMUq2UCu9N)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-093a8e409039> in <module>
      1 with WosClient( lite=True) as client:
      2     client.connect()
----> 3     wos.utils.query(client, str(x))

~\Anaconda3\lib\site-packages\wos\utils.py in query(wosclient, wos_query, xml_query, count, offset, limit)
     22     """Query Web of Science and XML query results with multiple requests."""
     23     results = [single(wosclient, wos_query, xml_query, min(limit, count-x+1), x)
---> 24                for x in range(offset, count+1, limit)]
     25     if xml_query:
     26         return [el for res in results for el in res]

~\Anaconda3\lib\site-packages\wos\utils.py in <listcomp>(.0)
     22     """Query Web of Science and XML query results with multiple requests."""
     23     results = [single(wosclient, wos_query, xml_query, min(limit, count-x+1), x)
---> 24                for x in range(offset, count+1, limit)]
     25     if xml_query:
     26         return [el for res in results for el in res]

~\Anaconda3\lib\site-packages\wos\utils.py in single(wosclient, wos_query, xml_query, count, offset)
     11     """Perform a single Web of Science query and then XML query the results."""
     12     result = wosclient.search(wos_query, count, offset)
---> 13     xml = _re.sub(' xmlns="[^"]+"', '', result.records, count=1).encode('utf-8')
     14     if xml_query:
     15         xml = _ET.fromstring(xml)

~\Anaconda3\lib\re.py in sub(pattern, repl, string, count, flags)
    190     a callable, it's passed the Match object and must return
    191     a replacement string to be used."""
--> 192     return _compile(pattern, flags).sub(repl, string, count)
    193 
    194 def subn(pattern, repl, string, count=0, flags=0):

TypeError: expected string or bytes-like object

Tags: inclientforstringcountwithutilsxml

热门问题