首先,我使用python从多个网站提取数据
import urllib
from bs4 import BeautifulSoup
import requests
import pandas as pd
import numpy as np
import traceback
pages = [str(i) for i in range(1,6)]
for page in pages:
# Read data from url
url1 = requests.get("https://www.top500.org/list/2018/06/?page="+ page)
# Parse the url using BeautifulSoup
soup= BeautifulSoup(url1.content, 'html.parser')
#Removing an encountered special characters
repString = "HLRS- Hochstleistungsrechenzentrum Stuttgart"
# Finding table data in url1
for record in soup.findAll('tr'):
tbltxt =""
for data in record.findAll('td'):
try:
tbltxt = tbltxt + data.text + ","
except:
tbltxt = tbltxt + replString+ ","
pass
print(tbltxt)
print()
后来我想把这些数据转换成csv文件。为此,我尝试在For循环之间插入以下代码,但遇到了一个错误
Rank= entry.Rank.text
Rank = Rank.replace(",", "|")
Site = entry.Site.text
Site = Site.replace(",", "|")
System = entry.System.text
System = System.replace(",", "|")
Cores = entry.Cores.text
Cores = Cores.replace(",", "|")
Rmax (TFlops/s) = entry.Rmax (TFlops/s).text
Rmax (TFlops/s) = Rmax (TFlops/s).replace(",","|")
Rpeak (TFlops/s) = entry.Rpeak (TFlops/s).text
Rpeak (TFlops/s) = Rpeaks (TFlops/s).replace(",","|")
Power (kW) = entry.Power (kW).text
Power (kW) = Power (kW).replace(",","|")
f1.write(Rank + "," + Site + "," + System + "," + Cores + "," + Rmax (TFlops/s) + "," + Rpeak (TFlops/s) + ","+ Power (kW) + "\n")
但是我说的是个错误
yntaxError: can't assign to function call (<ipython-input-22-043a1b549895>, line 25)
File "<ipython-input-22-043a1b549895>", line 25
Rmax (TFlops/s) = entry.Rmax (TFlops/s).text
SyntaxError: can't assign to function call
那么,谁能帮我摆脱这种局面呢
把它改成
问题是您试图将值分配给值(函数调用)
所有这些线路都有相同的问题:
Rmax(TFlops/s)请记住,“(“”)”在这里不被视为常规字符串字符
相关问题 更多 >
编程相关推荐