抱歉,如果这个问题与其他问题相似,我无法使任何其他解决方案发挥作用。我正在使用 beautifulsoup 抓取一个网站,并尝试从评论的表字段中获取信息:
<td>
<span class="release" data-release="1518739200"></span>
<!--<p class="statistics">
<span class="views" clicks="1564058">1.56M Clicks</span>
<span class="interaction" likes="0"></span>
</p>-->
</td>
Run Code Online (Sandbox Code Playgroud)
如何获得“观看次数”和“互动次数”部分?
我需要将地图组件提取到静态图像: http://www.bom.gov.au/water/landscape/#/sm/Relative/day/-35.30/145.17/5/Point////2018 /12/16/
此页面包含基于 Leaflet 的交互式网络地图,其中图层数据每天通过网络地图服务更新。提取的图像应包含地图上加载的任何图层。
这也需要自动化,这样就没有人会打开网络浏览器并访问该 URL。提取的图像将转到 Word 文档。
我是一名Python和nodejs程序员,但我无法通过BeautifulSoup for Python或Cheerio for nodejs进行网页抓取来实现它,因为地图不是img元素而是一些动态DIV。如何将地图组件作为图像?
我试图查看是否可以从 WU.com 读取数据表,但由于未找到表而收到类型错误。(这里也是网络抓取的第一次)还有另一个人在这里提出了与 WU 数据表非常相似的 stackoverflow 问题,但解决方案对我来说有点复杂。
import pandas as pd
df_list = pd.read_html('https://www.wunderground.com/history/daily/us/wi/milwaukee/KMKE/date/2013-6-26')
print(df_list)
Run Code Online (Sandbox Code Playgroud)
在密尔沃基的历史数据网页上daily observations,这是我尝试检索到 Pandas 中的
数据表 ( ):
任何提示都有帮助,谢谢。
我正在尝试抓取一个食谱网站,但在尝试将标签后的字符串分成不同的句子时遇到麻烦<br>。
为了更好地理解这个问题,我将向您展示我正在讨论的代码和输出。
\n\n以下是我正在处理的 HTML 片段。
\n\n<div class="opskriften">\r\n <p class="h3">Ingrediensliste</p>\r\n <p></p>\r\n<p>100 g. m\xc3\xa6lkechokolade<br>20 g. mini marshmallows<br>40 g. saltede peanuts</p>\r\n<p>\r\n\r\n </p></div>Run Code Online (Sandbox Code Playgroud)\r\n我想以某种方式分离标签后的每种成分<br>,这样我就可以进一步分离字符串,这样我最终可以获得一个包含 3 个不同列(数量、单位、成分)的表格。以下代码是我用来获取特定<p>标签的代码。
from bs4 import BeautifulSoup\n import requests \n r = requests.get("site")\n soup = BeautifulSoup(r.content)\n ingredients = soup.find(\'div\', class_=\'opskriften\')\n ingredientslist = ingredients.select_one("p:nth-oftype(2)")\n print(ingredientslist)\nRun Code Online (Sandbox Code Playgroud)\n\n输出如下:
\n\n<p>100 g. m\xc3\xa6lkechokolade<br/>20 g. mini marshmallows<br/>40 g. saltede peanuts</p>\nRun Code Online (Sandbox Code Playgroud)\n\n如何分离这些成分,以便能够应用正则表达式来匹配所有内容并将其放入如上所述的正确列中?
\n\n我尝试使用正则表达式,如下所示,但我得到了,AttributeError: \'NoneType\' object has no …
我想定期检查我的互联网速度,如果它下降到某个阈值,则重置我的路由器,这似乎可以修复我的 ISP“提供”的糟糕连接。
虽然可能有更简单的方法可以继续解决这个问题,但我认为我应该从 Fast.com 获取结果,它为我提供了我需要的结果,例如下载速度、上传速度以及到我附近的服务器的 ping 时间。
寻找任何指针。
在包含 HTML 的字符串中,我有几个想要用纯 href 值替换的链接:
from bs4 import BeautifulSoup
a = "<a href='www.google.com'>foo</a> some text <a href='www.bing.com'>bar</a> some <br> text'
soup = BeautifulSoup(html, "html.parser")
tags = soup.find_all()
for tag in tags:
if tag.has_attr('href'):
html = html.replace(str(tag), tag['href'])
Run Code Online (Sandbox Code Playgroud)
不幸的是,这会产生一些问题:
',但 beautifulsoup 将使用带引号 ( )str(tag)的标签创建。所以不会找到匹配的。"<a href="www.google.com">foo</a>replace()<br>被识别为<br/>. 再次replace()找不到匹配项。所以看来使用python的replace()方法不会给出可靠的结果。
有没有办法使用 beautifulsoup 的方法用字符串替换标签?
str(tag) 的附加值 =<a href="www.google.com">foo</a>
正如在这个问题中所讨论的,人们可以轻松地获得div某些类别的所有 s 。但在这里,我有一个我想要排除的类列表,并且想要获取列表中没有给出任何类的所有 div。
对于即
classToIgnore = ["class1", "class2", "class3"]
Run Code Online (Sandbox Code Playgroud)
现在想要获取所有不包含上述列表中的类的 div。我怎样才能做到这一点?
我正在尝试从网站 ( https://www.trackcorona.live ) 中提取冠状病毒,但出现错误。
\n\n这是我的代码:
\n\nresponse = requests.get(\'https://www.trackcorona.live\')\ndata = BeautifulSoup(response.text,\'html.parser\')\nli = data.find_all(class_=\'numbers\')\nconfirmed = int(li[0].get_text())\nprint(\'Confirmed Cases:\', confirmed)\nRun Code Online (Sandbox Code Playgroud)\n\n它给出了以下错误(尽管它在几天前工作),因为它返回一个空列表(li)
\n\n IndexError \n Traceback (most recent call last)\n<ipython-input-15-7a09f39edc9d> in <module>\n 2 data=BeautifulSoup(response.text,\'html.parser\')\n 3 li=data.find_all(class_=\'numbers\')\n----> 4 confirmed = int(li[0].get_text())\n 5 countries = li[1].get_text()\n 6 dead = int(li[3].get_text())\n\nIndexError: list index out of range\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\x8b
\n我当前的问题是,即使 Beautiful Soup 已安装在我的电脑上,导入也无法正常工作。我不断收到错误“没有名为‘bs4’的模块”。我目前正在使用 VS Code,但我启动了 python IDLE,但它也不起作用。如果有人知道发生了什么事,那将会有很大的帮助。
1. from pip._vendor import requests
2. from bs4 import BeautifulSoup
3.
4. url = 'https://someonerandomwebsite'
5. r = requests.get(url)
6. b_soup = BeautifulSoup(r.content, 'html.parser')
Run Code Online (Sandbox Code Playgroud)
这是我当前的错误
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
Run Code Online (Sandbox Code Playgroud) 我正在尝试从URL中抓取表格
我可以使用 Scrapestorm 工具抓取表格数据。我是 python 新手,无法从此URL获取数据。
from bs4 import BeautifulSoup
page = requests.get('https://pantheon.world/explore/rankings?show=people&years=-3501,2020')
soup = BeautifulSoup(page.text)
Run Code Online (Sandbox Code Playgroud)
Excel 中所需的输出:

是否可以从网页上抓取表格数据和图像?
beautifulsoup ×10
python ×10
web-scraping ×7
api ×1
cheerio ×1
class ×1
comments ×1
node.js ×1
pandas ×1
python-3.x ×1
regex ×1
selenium ×1