无法从Python中的HTML站点获取特定数据(3.6)(Can't get specific data from a HTML site in Python (3.6))

编程入门 行业动态 更新时间:2024-10-27 04:34:21
无法从Python中的HTML站点获取特定数据(3.6)(Can't get specific data from a HTML site in Python (3.6))

网页(关于足球和评分):

http://www.fantagazzetta.com/voti-serie-a

我尝试了什么:

如何从html页面中提取文本?

我试着在他的回答中使用用户JRodDynamite提供的代码(最后只是打印res并且不做for for thing)。 所以我需要编辑这部分代码(我猜):

res = soup.findAll("article", {"class": "listingItem"})

为了打印每个表的内容,我认为答案是:

res = soup.findAll("table", {"class": "table"})

但它不打印任何东西。 所以我需要你的帮助:我想从该网页收集数据(玩家的名字和评级),但我坚持这一点。 谢谢

Web page (about football and ratings) :

http://www.fantagazzetta.com/voti-serie-a

What i tried:

How to extract text from html page?

I tried using the code provided by the user JRodDynamite in his answer (and in the end just printing res and not doing the for thing). So i needed to edit just this part of the code (i guess):

res = soup.findAll("article", {"class": "listingItem"})

To print each table's content i thought the answer was:

res = soup.findAll("table", {"class": "table"})

But it's not printing anything. So I need your help: i would like to collect the data from that web page (player's name and rating) but i'm stuck on this point. Thanks

最满意答案

BeautifulSoup,请求等不执行Javascript,因此通过JS传递或呈现的任何数据都不可用。

对于JavaScript呈现的页面,您可以尝试使用dryscrape如下所示:

import dryscrape from bs4 import BeautifulSoup sess = dryscrape.Session() sess.visit('http://www.fantagazzetta.com/voti-serie-a#') s = BeautifulSoup(sess.body()) for a in s.find_all('table', {'class': 'table'}): print(a.text)

Dryscrape安装:

sudo pip install dryscrape

BeautifulSoup, requests, etc. does not execute Javascript, so any data delivered or rendered via JS will not be available to you.

For JavaScript rendered pages you can try with dryscrape like so:

import dryscrape from bs4 import BeautifulSoup sess = dryscrape.Session() sess.visit('http://www.fantagazzetta.com/voti-serie-a#') s = BeautifulSoup(sess.body()) for a in s.find_all('table', {'class': 'table'}): print(a.text)

Dryscrape installation:

sudo pip install dryscrape

更多推荐

本文发布于:2023-08-07 08:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:站点   数据   HTML   Python   site

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!