[问题] beautifulsoup 上的 find() takes no key

楼主: livehorse (新来的PTT肥宅)   2022-12-14 01:12:01
[问题] beautifulsoup 上的 find() takes no keyword argument 如何解决
请问各位神人
我最近刚开始学习如何用python爬文章于是挑了mobile01当目标
但是遇到了 find() takes no keyword argument不知道如何解决,我上卓查了一些类似的文章说要改成find_all,但是却返回”str”没有find_all这个attribute
更何况我只要爬一个特定目标应该不会是find_all才对
以下程式码
url="https://www.mobile01.com/newtopics.php?mode=newtopic"
mWeb = openpyxl.load_workbook("mobile.xlsx")
ws = mWeb.active
for a in range(1,6):
#建立一个requet物件,附加request Headers 的资讯,用request去打开网址
request=req.Request(url,headers={
"User-Agent":"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Mobile Safari/537.36"
})
with req.urlopen(request) as response:
data=response.read().decode("utf-8")
#解析原始码,取得每篇文章的标题(抓全区热门文章)
#data是网页的html原始码
#root表示整份网页
root=bs4.BeautifulSoup(data,"html.parser")#data是透过网络抓下来的资料(html原始码)丢给bs4会用html解析
titleLinks = root.find_all("div",class_="c-articleItem__title")
page = root.find("a",class_="c-pagination c-pagination
作者: lycantrope (阿宽)   2022-12-14 10:03:00
那不是bs4的find而是str的find
作者: blc (Anemos)   2022-12-14 11:24:00
inner是str

Links booklink

Contact Us: admin [ a t ] ucptt.com