我试图用此方法获得Ajax
响应,但它返回null
.
在发布答案之前确保你的解决方案有效。
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("example.com")
result = driver.execute_synce_script("""
function x()
{
var data = null
$.post('example.com/wp-admin/admin-ajax.php',{action:"load_links")
.done(function( response )
{
data = response
})
return data
}
return x()
""")
print(result)
试试这个:
from bs4 import BeautifulSoup
from selenium import webdriver
url = "<url>"
browser = webdriver.Chrome()
browser.get(url)
html = browser.page_source
soup = BeautifulSoup(html, 'lxml')
a = soup.find('section', 'wrapper')