Python Can';t使用BeautifulSoup从网站上刮取所有数据

Python Can';t使用BeautifulSoup从网站上刮取所有数据,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我正试图从中提取数据,但无法从该行中获取此特定信息: "p class="mt-3 pt-2 mb-0 rs-rel-085"": "6,10 % aller Aktien sind besser bewertet. (中文:“6.1%的股票评级更好。”) 我的代码适用于其余部分: from bs4 import BeautifulSoup as soup from urllib.request import Request, urlopen

我正试图从中提取数据,但无法从该行中获取此特定信息:

"p class="mt-3 pt-2 mb-0 rs-rel-085"": "6,10 % aller Aktien sind besser bewertet.
(中文:“6.1%的股票评级更好。”)

我的代码适用于其余部分:

from bs4 import BeautifulSoup as soup
from urllib.request import Request, urlopen

# Set up scraper
url = (f"https://aktie.traderfox.com/visualizations/US30303M1027/DI/facebook-inc")
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
html = soup(webpage, "html.parser")

#find company name
name_1 = html.find("span",attrs={"class":"h1 m-0"})
name = name_1.text.strip()

#Ticker+WKN+ISIN
WKN_1 = html.find("span",attrs={"class":"color-grey2 d-lg-none"})
WKN = WKN_1.text.strip().replace("[","").replace("]","")

#enterprise value
value_2 = html.find("div",attrs={"class":"col-5 col-lg-auto d-lg-table-cell align-top text-nowrap"})
value_1 = value_2.find("td")
enterprise_value = value_1.text.strip()

#P/E, P/S, div. yield
fin_all = html.find_all("span",attrs={"class":"d-block d-sm-inline d-lg-block fs-rel-110"})
fin_pe = fin_all[0]
PE = fin_pe.text.strip()
fin_ps = fin_all[1]
PS = fin_ps.text.strip()
fin_div20 = fin_all[2]
div20 = fin_div20.text.strip()
fin_div19 = fin_all[3]
div19 = fin_div19.text.strip()

#Performance since year X and avg. return
perf3 = html.find_all("div",attrs={"class":"col-auto py-2 fs-080 color-grey2"})
perf2 = perf3[0]
perf1 = perf3[1]
perf_h = perf2.text.strip()
perf_d = perf1.text.strip()
perf_1 = html.find_all("div",attrs={"class":"col-auto py-2 fs-125 fs-lg-110 fs-xl-125"})
perf_2 = perf_1[0]
perf_hist = perf_2.text.strip()
perf_4 = perf_1[1]
perf_avg = perf_4.text.strip()
perf_year = perf_h[23:27]

print(name)
print(WKN)
print(enterprise_value)
print(PE,PS, div20, div19)
print(perf_year, perf_hist, perf_avg)

5,95
根据通过单独的JSON请求获得的百分比分数计算得出。该值计算为
100-(100*分数)


我建议您打印出
json\u数据
,以便更好地理解返回数据的格式。

我认为该部分动态加载了JS,因此您无法使用bs4。也许你可以试试硒谢谢你,马丁·埃文斯!这正是我要找的。不客气!
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
from urllib import parse
import json

# Set up scraper
url = (f"https://aktie.traderfox.com/visualizations/US30303M1027/DI/facebook-inc")
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
soup = BeautifulSoup(webpage, "html.parser")

# << Your code here to get other items >>

# Locate the stock ID and request the JSON data for it
stock_id = soup.find('span', attrs={"data-id" : True})['data-id']
data = parse.urlencode({"stock_id" : stock_id}).encode()
req_fa =  Request("https://aktie.traderfox.com/ajax/getFactorAnalysis.php", data=data)
json_data = json.loads(urlopen(req_fa).read())

umsatzwachstum_growth = 100 - (100 * json_data["data"]["scores"]["salesgrowth5"]["score"])
eps_growth = 100 - (100 * json_data["data"]["scores"]["epsgrowth5"]["score"])
print(f"{umsatzwachstum_growth:.2f}, {eps_growth:.2f}")
5.95, 3.55