首页 > 解决方案 > 如何使用 python 3.6 抓取 jquery 代码?

问题描述

我需要帮助,我想抓取这个网站。我正在使用BeautifulSouprequests但我无法从图片中获得价值。

截屏

import requests
from bs4 import BeautifulSoup

my_url = 'https://partneredge.sap.com/content/partnerfinder/search.html#/'
page = requests.get(my_url)
page_soup = BeautifulSoup(page.content, "lxml")

trazenje = page_soup.find_all('header.search-result__head')
print(trazenje)

结果我得到空列表,没有错误!

链接到网站

标签: pythonpython-3.xweb-scrapingbeautifulsouppython-requests

解决方案


正如@abarnert 所提到的,您可能需要使用Selenium python 绑定之类的东西来获取该内容:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://partneredge.sap.com/content/partnerfinder/search.html#/')

table = driver.find_elements_by_xpath('//article//header//a')

results = []
for tag in table:
    results.append(tag.text)
print(results)

这会产生以下输出:

['Accenture', 'Capgemini AB', 'Deloitte Inc.', 'IBM Corporation International Technical', 'itelligence AG', 'SEIDOR, S.A.', 'GAVDI A/S', 'Navigator Business Solutions, Inc.', 'Delaware Consulting US Inc.', 'Ernst & Young LLP']

我会说,如果速度是一个因素,这个选项会很慢,但很容易设置。


推荐阅读