Python中文
首页
教程
问答
标签
搜索
登录
注册
使用Python-ulsoupin-beauthout表提取值?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正试图编写一个Python脚本,从位于这个页面的表中提取一些标记值:<a href="https://azure.microsoft.com/en-us/pricing/details/virtual-machines/windows/" rel="nofollow noreferrer">https://azure.microsoft.com/en-us/pricing/details/virtual-machines/windows/</a></p> <p>我已经包含了一个HTML源代码的屏幕截图,但是我无法找到如何提取第6、7、8和9列的价格数据。下面是我已经写过的代码。在</p> {<1分$ <div^{cl2}$ <pre class="snippet-code-html lang-html prettyprint-override"><code>import requests import pandas as pd from bs4 import BeautifulSoup url = 'https://azure.microsoft.com/en-us/pricing/details/virtual-machines/windows/' response = requests.get(url) soup = BeautifulSoup(response.content, 'html.parser') table1 = soup.find_all('table', class_= 'sd-table') #writing the first few columns to text file with open('examplefile.txt', 'w') as r: for row in table1.find_all('tr'): for cell in row.find_all('td'): r.write(cell.text.ljust(5)) r.write('\n')</code></pre> </div> </div> <p>我最终尝试提取每行的所有值,并将其保存到Pandas数据帧或CSV中。谢谢。 <a href="https://i.stack.imgur.com/6QbAI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6QbAI.jpg" alt="enter image description here"/></a></p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<pre><code>soup = find_all ('table', {'class':'sd-table'}) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
找出给定numb上下最近的元素
5 回答
找出给定N个数中K的倍数
3 回答
找出给定列表中哪个坐标是虚坐标?
3 回答
找出给定多边形边的两个区域是否相交
7 回答
找出给定对象的可用属性(和方法)的最佳方法是什么?
4 回答
找出给定数字的可能组合
6 回答
找出给定数据中每列中缺少值的百分比
6 回答
找出给定范围内的所有素数
6 回答
找出编码不正确的数据库条目
2 回答
找出肯肯拼图“乘法”域中所有可能的因素
10 回答
找出脚本的下载位置
4 回答
找出芹菜任务是否存在
5 回答
找出行之间的绝对差异并将其与其他行进行比较
4 回答
找出表中for项和rang中for数的区别
10 回答
找出表单是否已提交或页面是否已刷新
2 回答
找出要删除的内容
2 回答
找出谁使用python登录linux
1 回答
找出谁在学生中得分最高
4 回答
找出谁杀了一个python windows服务
4 回答
找出起始时间和结束时间之间的值
3 回答