使用 Python 和 BeautifulSoup 进行问题抓取

vg

我已经刮了这个网站一年了,但是他们最近改变了网站的布局,由于某种原因我不能让它工作了。我正在使用 Python 和 BeautifulSoup。

我基本上是想从这个链接获取表格中的数据:https ://www.loto.ro/?p=3872

这是用于处理旧布局的代码,我对其进行了调整以适应网站的当前布局:

            website_result = requests.get("https://www.loto.ro/?p=3872")
            src = website_result.content
            soup = BeautifulSoup(src, 'lxml')

            for i in range(0, 8):
                table_title = soup.select(".content .content-info .rezultate-extrageri-content.resultDiv .button-open-details")[i].get_text().strip()

                if "6/49" in table_title:
                    images = soup.select(".content-info .rezultate-extrageri-content.resultDiv "
                                         ".info-rezultat .numere-extrase img[src]")

                    if len(images) > 0:
                        table = soup.select(".content .content-info .rezultate-extrageri-content.resultDiv .results-table")[i]

在调试模式下,我的代码卡在“table_title”行,没有给我任何错误或回溯,所以我什至不知道问题是什么。

有任何想法吗?谢谢。

巴杜克

结果形式的 URL确实是新的,因为其中包含“newLottoSite”。

试试这个:

import pandas as pd
import requests
from tabulate import tabulate

new_url = "https://www.loto.ro/loto-new/newLotoSiteNexioFinalVersion/web/app2.php/jocuri/649_si_noroc/rezultate_extragere.html"

headers = {
    "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36",
    "referer": "https://www.loto.ro/?p=3872",
}

df = pd.read_html(requests.get(new_url, headers=headers).text, flavor="lxml")[0]
print(tabulate(df, headers="keys", tablefmt="psql"))

这应该输出:

+----+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
|    | CAT.                                  | Numar castiguri                       | Valoare castig                        | Report                                |
|----+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------|
|  0 | I (6/6)                               | REPORT                                | 272.80920                             | 4.289.31280                           |
|  1 | II (5/6)                              | 5                                     | 18.18728                              | -                                     |
|  2 | III (4/6)                             | 285                                   | 31907                                 | -                                     |
|  3 | IV (3/6)                              | 4.563                                 | 3000                                  | -                                     |
|  4 | Fond total de castiguri: 4.608.075,60 | Fond total de castiguri: 4.608.075,60 | Fond total de castiguri: 4.608.075,60 | Fond total de castiguri: 4.608.075,60 |
+----+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用python和BeautifulSoup进行网络抓取

Python - 使用 BeautifulSoup 和 Urllib 进行抓取

使用python,BeautifulSoup和pandas'read_html'进行网页抓取的问题

使用python 2.7和beautifulsoup 4进行网站抓取

使用Beautifulsoup和Python进行Web抓取不起作用

使用Python和beautifulsoup进行Web抓取:BeautifulSoup函数可以保存什么?

使用 Python 和 Beautiful Soup 进行抓取时 div 的问题

使用 BeautifulSoup 和 json 进行网页抓取

如何使用BeautifulSoup和Python抓取页面?

使用 Beautifulsoup 和 Python 抓取复杂的表格

使用 Python 和 BeautifulSoup 抓取 alt 标签

使用Python和BeautifulSoup从HTML抓取数字

使用 BeautifulSoup 和 Python 抓取表格

使用 beautifulsoup 进行网页抓取的问题

使用 BeautifulSoup 进行简单且少量的抓取中的标签和类的 HTML 问题

使用Python,BeautifulSoup进行Web抓取

使用 Python BeautifulSoup 进行网页抓取

使用 BeautifulSoup 进行网页抓取 -- Python

使用python 3.6和beautifulsoup进行网络抓取-获取无效的URL

Beautifulsoup 的 Python 抓取问题

使用 BeautifulSoup 抓取问题

无法使用 beautifulsoup 和 requests 进行网络抓取

使用 Selenium 和 BeautifulSoup 进行 Zillow 网页抓取

使用 Selenium 和 BeautifulSoup 进行网页抓取返回空列表

网页抓取 - 从使用 BeautifulSoup 和 Python 的类中获取文本?

如何使用Python和BeautifulSoup抓取多个Google页面

无法使用python和beautifulsoup抓取网页中的某些href

使用 python 和 BeautifulSoup 抓取不完整的标签

使用 Python、Selenium 和 BeautifulSoup 来抓取标签的内容?