嗨,我正试图从这个网站上刮表https://vcx-forum.org/score,当我试图用漂亮的汤刮表时,它显示错误'NoneType' object has no attribute 'find'
下面是我的代码片段
from bs4 import BeautifulSoup
import requests
import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
driver.get("https://vcx-forum.org/score")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
key = {}
data = []
html = driver.page_source
soup = BeautifulSoup(html, 'lxml')
for tag in soup.find_all('div', class_="vcx-ranking__body js-vcx-ranking-body"):
for span in tag.find_all('div', class_="t-row"):
for row in span:
model = row.find("div", class_="t_cell colCamera").find("a").text
rating = row.find("div", class_="t_cell colScore colVCX active").find("span",
class_="score_numeric").text
image_quality = row.find("div", class_="t_cell colScore colImageQuality").text
sunny = row.find("div", class_="t_cell colScore colBright").text
indoor = row.find("div", class_="t_cell colScore colMid").text
night = row.find("div", class_="t_cell colScore colImageLow").text
flash = row.find("div", class_="t_cell colScore colFlash").text
zoom = row.find("div", class_="t_cell colScore colZoom").text
perform = row.find("div", class_="t_cell colScore colHandling").text
key = {'model':[model],
'image_quality':[image_quality],
'sunny':[sunny],
'indoor':[indoor],
'night':[night],
'flash':[flash],
'zoom':[zoom],
'perform':[perform]
}
df = pd.DataFrame(key, columns = ['model', 'rating','image_quality', 'sunny',
'indoor', 'night', 'flash', 'zoom', 'perform'])
我尝试在for span行之后打印(span.text),但它只显示t-row的div类中的所有内容,我希望所有内容都能很好地分隔为列名
编辑:
AttributeError Traceback (most recent call last)
<ipython-input-63-f1da6a7e61dd> in <module>
16 for span in tag.find_all('div', class_="t-row"):
17 for row in span:
---> 18 model = row.find("div", class_="t_cell colCamera").find("a").text
19 rating = row.find("div", class_="t_cell colScore colVCX active").find("span",
20 class_="score_numeric").text
AttributeError: 'NoneType' object has no attribute 'find'
我已经对你的代码做了一些修改。它现在运行良好
输出:
相关问题 更多 >
编程相关推荐