Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python beautifulsoup find方法返回:TypeError:find()不接受关键字参数_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python beautifulsoup find方法返回:TypeError:find()不接受关键字参数

Python beautifulsoup find方法返回:TypeError:find()不接受关键字参数,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我有一个html文件,我尝试使用find方法从这个文件返回获取的数据,下面是我的代码 更新:我删除了find()方法之后的.text,它返回None!但我确信这个值在文件中 from bs4 import BeautifulSoup r= open('D:\IT\programming\Python\Data-science\WebScraping\ParseFiles\\test.html', encoding="utf-8") soup = BeautifulSoup(r, 'html.pa

我有一个html文件,我尝试使用find方法从这个文件返回获取的数据,下面是我的代码

更新:我删除了find()方法之后的.text,它返回None!但我确信这个值在文件中

from bs4 import BeautifulSoup
r= open('D:\IT\programming\Python\Data-science\WebScraping\ParseFiles\\test.html', encoding="utf-8")
soup = BeautifulSoup(r, 'html.parser').text
data = soup.find('span', class_='a-column a-span4 a-text-right a-span-last')
print(data)
它返回以下错误:

Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/web_scraping/get_book_price.py", line 13, in <module>
    data = soup.find('span', class_='a-column a-span4 a-text-right a-span-last').span
TypeError: find() takes no keyword arguments
回溯(最近一次呼叫最后一次):
文件“C:/Users/Administrator/PycharmProjects/web_scraping/get_book_price.py”,第13行,在
data=soup.find('span',class='a-column a-span4 a-text-right a-span-last')。span
TypeError:find()不接受关键字参数

您不是在调用BeautifulSoup的
.find()
,而是在普通字符串对象上调用它(BeautifulSoup对象中的
.text
属性)。删除
。text
仅使用
soup=BeautifulSoup(r,'html.parser')
尝试以下操作:
数据=soup.find('span',{'class':'a-column a-span4 a-text-right a-span-last'})
是否不希望在文件地址的末尾有一个\而不是当前删除的\\I。text和代码返回无!您不是在调用BeautifulSoup的
.find()
,而是在一个普通的字符串对象上调用它(BeautifulSoup对象中的
.text
属性)。删除
.text
仅使用
soup=BeautifulSoup(r,'html.parser')
尝试以下操作:
data=soup.find('span',{'class':'a-column a-span4 a-text-right a-span-last'))
是否不希望在文件地址的末尾有一个\作为当前\\I removed.text的反面。如果代码返回none,则返回none!