python萌新问题

[复制链接]
查看11 | 回复4 | 2021-1-27 07:15:43 | 显示全部楼层 |阅读模式
importrequests
frombs4importBeautifulSoup
res=requests.get('https://www.dxomark.com/category/smartphone-reviews')
html=res.text
soup=BeautifulSoup(html,'html.parser')
items=soup.find_all(class_='selectionWrapmobile')
foriteminitems:
deviceScore=item.find_all('class=deviceScore')
deviceName=item.find_all('h3')
foriindeviceScore:
print(i,end=('')
这个运行下来没有结果,没有报错。想问下哪里出问题了?
分 -->
回复

使用道具 举报

千问 | 2021-1-27 07:15:43 | 显示全部楼层
deviceScore=item.find_all('class=deviceScore')
这里写错了。导致没有匹配到内容。可修改为class_="deviceScore"

importrequests
frombs4importBeautifulSoup
res=requests.get('https://www.dxomark.com/category/smartphone-reviews')
html=res.text
soup=BeautifulSoup(html,'html.parser')
items=soup.find_all(class_='selectionWrapmobile')
foriteminitems:
deviceScore=item.find_all(class_="deviceScore")
deviceName=item.find_all('h3')
foriindeviceScore:
print(i,end=(''))

回复

使用道具 举报

千问 | 2021-1-27 07:15:43 | 显示全部楼层
不好意思啊但是改过之后还是错的
File"c:/Users/22531/OneDrive/桌面/Untitled-2.py",line8
deviceScore=item.find_all(class='deviceScore')
^
SyntaxError:invalidsyntax

回复

使用道具 举报

千问 | 2021-1-27 07:15:43 | 显示全部楼层
引用1楼--lx的回复:deviceScore=item.find_all('class=deviceScore')
这里写错了。导致没有匹配到内容。可修改为class_="deviceScore"

importrequests
frombs4importBeautifulSoup
res=requests.get('https://www.dxomark.com/category/smartphone-reviews')
html=res.text
soup=BeautifulSoup(html,'html.parser')
items=soup.find_all(class_='selectionWrapmobile')
foriteminitems:
deviceScore=item.find_all(class_="deviceScore")
deviceName=item.find_all('h3')
foriindeviceScore:
print(i,end=(''))
不好意思还是错的
回复

使用道具 举报

千问 | 2021-1-27 07:15:43 | 显示全部楼层
引用1楼--lx的回复:deviceScore=item.find_all('class=deviceScore')
这里写错了。导致没有匹配到内容。可修改为class_="deviceScore"

importrequests
frombs4importBeautifulSoup
res=requests.get('https://www.dxomark.com/category/smartphone-reviews')
html=res.text
soup=BeautifulSoup(html,'html.parser')
items=soup.find_all(class_='selectionWrapmobile')
foriteminitems:
deviceScore=item.find_all(class_="deviceScore")
deviceName=item.find_all('h3')
foriindeviceScore:
print(i,end=(''))
我重新试了一下,系统告诉我说unexpectedEOFwhileparsing
这是什么问题?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行