【问题标题】:Unable to get data using requests, no data source in network tab无法使用请求获取数据,网络选项卡中没有数据源
【发布时间】:2019-08-12 03:20:20
【问题描述】:

您好,我正在尝试使用请求模块和 BS4 加载 https://www.ubytovanienaslovensku.eu/,但我无法获取所需的数据。似乎数据正在使用 js 加载,但我无法在 Chrome 开发工具网络选项卡中看到任何数据源。


import requests
import bs4
import lxml
url ='https://www.ubytovanienaslovensku.eu'
res = requests.get(url)
soup = bs4.BeautifulSoup(res.content, 'lxml')
print(soup.get_text())

我看到网站上的数据是即时加载的,但我没有看到该数据的任何来源。
我需要网站上的列表。不仅仅是只有脚本标签的基本html

【问题讨论】:

  • I am unable to get the required data: 需要什么数据?更多上下文会更好。
  • 感谢您的评论,我需要访问加载的列表,只有它们的 URL 和标题

标签: python-3.x dom web-scraping beautifulsoup python-requests


【解决方案1】:

它来自一个 websocket,所以你必须搜索 WS 消息面板:

您将无法通过请求获得它。你可以试试 Selenium。

【讨论】:

  • 有兴趣知道+
【解决方案2】:

您可以结合使用 pyppeteerasyncio 从该站点异步获取列表。

import asyncio
from pyppeteer import launch

url = "https://www.ubytovanienaslovensku.eu/"

async def get_listings(link):
    wb = await launch({"headless": False})
    [page] = await wb.pages()
    await page.goto(link)
    await page.waitForSelector('#home-rentals')
    containers = await page.querySelectorAll('.rental-item')
    for container in containers:
        title = await container.querySelectorEval('span.caption','e => e.innerText')
        link = await page.evaluate('e => e.href',container)
        print(title,link)

asyncio.get_event_loop().run_until_complete(get_listings(url))

输出如下:

VIP SK Drevenica - Liptovská Štiavnica (max. 75) https://www.ubytovanienaslovensku.eu/chalupky-u-babky
VIP SK Drevenica - Mýto pod Ďumbierom (max. 28) https://www.ubytovanienaslovensku.eu/chata-zinka
VIP SK Drevenica - Liptovský Trnovec (max. 72) https://www.ubytovanienaslovensku.eu/liptovske-chaty
VIP SK Drevenica - Ružomberok (max. 90) https://www.ubytovanienaslovensku.eu/chaty-liptovo

【讨论】:

  • 完美、全面、完整
猜你喜欢
  • 2021-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-07
  • 1970-01-01
  • 2017-09-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多