python - Python中的网络爬虫
问题描述
我的问题是是否有可能得到一个像这样的跨度内的数字:
<html junk>
<div class="test">
<span>
55
</span>
</div>
</html junk>
如您所见,span 没有类或 id。
我当前的代码只是刮板的默认代码(删除了用户代理和 URL):
import requests
from bs4 import BeautifulSoup
URL = ''
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 it
title = soup.find('')
print(title)
解决方案
如果我正确理解了您的问题,您是否正在尝试获取两个跨度标签之间的数字?如果是这样,您可以这样做。
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)
推荐阅读
- java - 应用程序因 StackOverflow 错误而崩溃
- c# - Azure 存储帐户使用托管标识和 C# 进行身份验证
- javascript - React Native Deep Link 传递未定义的参数
- npm - 当包 json 中有私有存储库时,Github 操作显示错误
- sql - 如何在 Oracle 中与 Group By 和 Order By 一起使用?
- r - 在 R shiny 中,为什么我在对 renderUI 进行简单的适配后会收到错误消息?
- matlab - 实时运行 Simulink exe
- c# - WPF 无法正确显示图像
- angular - 如何从`fromEvent`方法获取最后一个事件
- hadoop - 在 Flink 中以编程方式配置 S3 选项