为了获得我的wordlist
中每个单词的搜索结果数,我写了以下内容:
with open ("C:\wordslist.txt") as f:
lines = f.readlines()
def bingSearch(word):
r = requests.get('http://www.bing.com/search',
params={'q':'"'+word+'"'}
)
soup = BeautifulSoup(r.text, "html.parser")
return (soup.find('span',{'class':'sb_count'}))
matches = [re.search(regex,line).groups() for line in lines]
for match in matches:
searchWord = match[0]
found = bingSearch(searchWord)
print (found.text)
它工作得很好,而且我得到了准确的结果,除了包含特殊字符的单词之外,例如单词:"número"
。在
如果我调用bingSearch("número")
我会得到一个准确的结果。
如果我调用bingSearch(match[0])
(其中打印match[0]
产生{
我试过str(match[0])
,match[0].encode(encoding="UTF-8")
,但是没有成功。在
有什么想法吗?在
当你打开你的文件时,试着直接给出编码,这会有不同
with open ("C:\wordslist.txt", encoding="utf-8") as f:
https://docs.python.org/3/library/functions.html#open
相关问题 更多 >
编程相关推荐