Python 漂亮的汤面师,有班级和身份证

Python 漂亮的汤面师,有班级和身份证,python,python-2.7,web-scraping,beautifulsoup,Python,Python 2.7,Web Scraping,Beautifulsoup,我是初学者,想问一下如何使用beautiful soup从以下类型的代码中提取数据: <div class="about-book" id="aboutbook"> Blah blah blah </div> 废话废话 当有不同id的“about book”和不同类名的“about book”时,如何获取“Blah Blah Blah Blah”。我想要的是类名和id的组合。试试“div#about book.about book” 使用beautifulsoup,

我是初学者,想问一下如何使用beautiful soup从以下类型的代码中提取数据:

<div class="about-book" id="aboutbook">
Blah blah blah
</div>

废话废话
当有不同id的“about book”和不同类名的“about book”时,如何获取“Blah Blah Blah Blah”。我想要的是类名和id的组合。

试试
“div#about book.about book”

使用beautifulsoup,您可以这样编写:

soup = BeautifulSoup(html) soup.find_all("div", class_="about-book", id="aboutbook")
试试
“div#aboutbook.about book”

使用beautifulsoup,您可以这样编写:

soup = BeautifulSoup(html) soup.find_all("div", class_="about-book", id="aboutbook")
试试
“div#aboutbook.about book”

使用beautifulsoup,您可以这样编写:

soup = BeautifulSoup(html) soup.find_all("div", class_="about-book", id="aboutbook")
试试
“div#aboutbook.about book”

使用beautifulsoup,您可以这样编写:

soup = BeautifulSoup(html) soup.find_all("div", class_="about-book", id="aboutbook")

您能否举例说明如何在beautifulsoup bcz中编写相同的代码?基于文档,它似乎不起作用:
soup=beautifulsoup(html)soup.find_all(“div”,class=“about book”,id=“aboutbook”)
您能否举例说明如何在beautifulsoup bcz中编写相同的内容?基于文档,它似乎不起作用:
soup=beautifulsoup(html)soup.find_all(“div”,class=“about book”,id=“aboutbook”)
您能否举例说明如何在beautifulsoup bcz中编写相同的内容?基于文档,它似乎不起作用:
soup=beautifulsoup(html)soup.find_all(“div”,class=“about book”,id=“aboutbook”)
你能举例说明如何在beautifulsoup bcz中编写相同的代码吗?基于文档,它似乎不起作用:
soup=beautifulsoup(html)soup.find_all(“div”,class=“about book”,id=“aboutbook”)
回溯(最后一次调用):打印文件“bigpm.py”,第31行([x.text代表汤中的x.find_all(“div”,attrs={“class”):“about book”})如果x[“id”]=“aboutbook”])文件“C:\Python27\lib\site packages\bs4\element.py”,在getitem return self.attrs[key]keyror:“id”应该是。getyou还可以执行
attrs={id':“aboutbook”}
并保存一个
if
语句…回溯(最近的调用):文件“bigpm.py”,第31行,打印([x.text代表汤中的x.find_all(“div”,attrs={“class”:“about book”})如果x[“id”]==“aboutbook”])文件“C:\Python27\lib\site packages\bs4\element.py”,第905行,在getitem返回self.attrs[key]键错误:“id”应该是。getyou还可以执行
attrs={id':“aboutbook”,“class':“about book”}
并保存一个
if
语句…回溯(最后一次调用):打印文件“bigpm.py”,第31行([x.text代表汤中的x.find_all(“div”,attrs={“class”:“about book”})如果x[“id”]=“aboutbook”])文件“C:\Python27\lib\site packages\bs4\element.py”,第905行,在getitem return self.attrs[key]KeyError:'id'应该是。getyou也可以执行
attrs={'id':'aboutbook','class':'about book'}
并保存一个
if
语句…回溯(最近一次调用):文件“bigpm.py”,第31行,打印([x.text代表汤中的x.find_all(“div”,attrs={“class”):“about book”})如果x[/id==“aboutbook”])文件”C:\Python27\lib\site packages\bs4\element.py”,第905行,在getitem中返回self.attrs[key]keyrerror:'id'应该是。getyou也可以执行
attrs={'id':'aboutbook','class':'about book'}
并保存一个
if
语句。。。