为了账号安全,请及时绑定邮箱和手机立即绑定

Python 中的网络爬虫

Python 中的网络爬虫

四季花海 2023-09-05 17:34:09
我的问题是是否有可能获得一个在这样的范围内的数字:<html junk> <div class="test">     <span>     55     </span> </div></html junk>正如您所看到的,span 没有类或 id。我当前的代码只是抓取工具的默认代码(删除了用户代理和 URL):import requestsfrom bs4 import BeautifulSoupURL = ''headers = {"User-Agent": ''}page = requests.get(URL, headers=headers)soup = BeautifulSoup(page.content, 'html.parser')#Here is where the "55" should be found (the number is going to change over time so im not excactly looking for ittitle = soup.find('') print(title)
查看完整描述

1 回答

?
UYOU

TA贡献1878条经验 获得超4个赞

如果我正确理解你的问题,你正在尝试获取两个跨度标签之间的数字?如果是这样,你可以这样做。


import requests

from bs4 import BeautifulSoup


URL = ''


headers = {"User-Agent": ''}


page = requests.get(URL, headers=headers)


soup = BeautifulSoup(page.text, 'html.parser')


#Here is where the "55" should be found (the number is going to change over time so im not excactly looking for it

title = soup.find('span').getText() 


print(title)


查看完整回答
反对 回复 2023-09-05
  • 1 回答
  • 0 关注
  • 65 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信