我对编程很陌生,我正试着刮一个网站。
该网站是一个在线赌场(https://www.888casino.it/live-casino/#filters=all-roulette),我只需要在显示的数字中刮一次(包含在特定位置上的数字大约每30秒变化一次,但我稍后会考虑这个问题)。
<div class="sc-qbELi jLgZIw">
<span>2</span>
</div>我想刮的数字包含在span标记中,因为它们没有id或类,所以我无法找到它们。因此,我讨论如何定位包含span标记的div标记,然后使用诸如.contents、.next_element或.children等函数刮取span标记中包含的数字。
为了定位div标记(它不是html代码中的第一个div标记,它位于许多其他div标记中):
从bs4导入BeautifulSoup
导入请求
导入urllib.request
url = 'https://www.888casino.it/live-casino/#filters=all-roulette‘
响应= requests.get(url)
"html.parser") = BeautifulSoup(response.text,response.text)
。
div_tag = soup.findAll('div', class_='sc-qbELi jLgZIw')
div_tag = soup.find("div", class_="sc-qbELi jLgZIw")
div_tag = soup.select("div.jLgZIw.sc-qbELi")问题是,当打印时,这些代码的输出分别是:,无,。因此,当我尝试将.children或.content添加到div_tag中时,我也没有得到任何东西。
如果你能帮我弄清楚怎么做,我会很高兴的。谢谢你的关注
发布于 2021-04-02 02:48:29
我不得不用硒。该网站很可能是动态加载的。
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome('chromedriver.exe', options=chrome_options)
url = 'https://www.888casino.it/live-casino/#filters=all-roulette'
driver.get(url)
time.sleep(5)
html = driver.page_source
soup = BeautifulSoup(html, "html.parser")使用
len(soup.find_all(class_="sc-qbELi jLgZIw")) 长度为50。你必须想办法找出正确的答案,但这会产生输出,让你开始
https://stackoverflow.com/questions/66913271
复制相似问题