Even if I bring it after running Python JavaScript, there are no elements in the div

Asked 2 years ago, Updated 2 years ago, 17 views

After loading the container, it runs in JavaScript You have to crawl the binding page over there.

So I'm going to scratch it after loading

#!/usr/bin/python
# # -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
from selenium import webdriver


"""
1.
"""
driver = webdriver.Chrome("C:\\chrome\\chromedriver.exe")
driver.get('http://~~~~~~')
html = driver.page_source

soup = BeautifulSoup(html,"lxml")

print(soup)



ranks = soup.findAll("div", id="Grid")

I did it as above, but it doesn't work. What's the problem?

python

2022-09-22 11:39

1 Answers

Replace id="Grid" with {"id":"Grid"}.

ranks = soup.findAll("div", {"id":"Grid"}) 

If you just want to scratch the elements in the div,

ranks = soup.findAll("div", {"id":"Grid"}).findChildren()

Try it.

Please refer to the stack overflow question below.

How to find children of nodes using Beautiful Soup


2022-09-22 11:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.