Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么';查找();方法仅返回第一个值?如何获取所有值?_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 为什么';查找();方法仅返回第一个值?如何获取所有值?

Python 为什么';查找();方法仅返回第一个值?如何获取所有值?,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我试图从url中删除所有值,但我只得到第一个值。有什么问题?如何获取所有值 import requests #Importing beautiful soup for scraping from bs4 import BeautifulSoup url='http://howstat.com/cricket/Statistics/Players/PlayerOverviewSummary.asp?PlayerID=4104' data = requests.get(url) html_cod

我试图从url中删除所有值,但我只得到第一个值。有什么问题?如何获取所有值

import requests
#Importing beautiful soup for scraping
from bs4 import BeautifulSoup

url='http://howstat.com/cricket/Statistics/Players/PlayerOverviewSummary.asp?PlayerID=4104'

data = requests.get(url)
html_code = data.content
# print(html_code)

#Parser
soup = BeautifulSoup(html_code, 'html.parser')

title2 = soup.find(class_='FieldValue')

abcd=[]

for i in title2.stripped_strings:
    abcd.append(i)


print(abcd)
试试这个:

import requests
from bs4 import BeautifulSoup

url = 'http://howstat.com/cricket/Statistics/Players/PlayerOverviewSummary.asp?PlayerID=4104'
data = requests.get(url)
html_code = data.content
soup = BeautifulSoup(html_code, 'html.parser')
title2 = soup.find_all(class_='FieldValue')

print([i.getText(strip=True) for i in title2])
输出:

['17', '0', '974', '243', '57.29', '4', '3', '0', '116', '22', '55.98', '0.0', '0', '0', 'N/A', '0', '0', '', '', '', 'N/A', '7', '2', '3', '0', '0', '0', '0', '0', '0', '', '3', '0', '36', '32', '12.00', '0', '0', '0', '6', '0', '92.31', '0.0', '0', '0', 'N/A', '0', '0', '', '', 'N/A', '1', '1', '0', '0', '0', '0', '', '20', '0', '1010', '243', '50.50', '4', '3', '0', '122', '22', '56.77', '0.0', '0', '0', 'N/A', '0', '0', '0/999', '', 'N/A', '8', '2', '0', '0', '0', '0', 'N/A', '80', '3', '1648', '106', '21.40', '7', '1', '5', '155', '67', '134.53', '0.0', '0', '0', 'N/A', '0', '0', '', '', 'N/A', '32', '2', '0', '0', '0', '0', '']

如果有一个
find_all
方法就好了。请阅读文档。。。