Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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_Python 3.x_Beautifulsoup - Fatal编程技术网

Python 从网页中删除表格数据

Python 从网页中删除表格数据,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,我正在努力学习python和葡萄牙语,所以我想我可以一石二鸟 下面是一个示例。我想下载蓝色表格中的数据,因此第一个这样的表格称为Presente,下一个表格称为Pretérito Perfeito,依此类推 下面是我的代码,但我正在努力。我的results变量确实包含我需要的数据,但是我无法尝试提取准确的位,因为div标记没有id 有更好的方法吗 import requests from bs4 import BeautifulSoup URL = 'https://conjugator

我正在努力学习python和葡萄牙语,所以我想我可以一石二鸟

下面是一个示例。我想下载蓝色表格中的数据,因此第一个这样的表格称为Presente,下一个表格称为Pretérito Perfeito,依此类推

下面是我的代码,但我正在努力。我的results变量确实包含我需要的数据,但是我无法尝试提取准确的位,因为div标记没有id

有更好的方法吗

 import requests
 from bs4 import BeautifulSoup

 URL = 'https://conjugator.reverso.net/conjugation-portuguese-verb-ser.html'
 page = requests.get(URL)
 soup = BeautifulSoup(page.content, 'html.parser')
 results = soup.find(id='ch_divSimple')
 mychk = results.prettify()
 tbl_elems = results.find_all('section', class_='wrap-verbs-listing')

他们没有ID,但他们有类。你可以做:

results.find_all("div", "blue-box-wrap")
其中
蓝框包装
是一个类

它将返回长度为22的
ResultSet
对象,因为有22个蓝色表格。您可以通过索引选择所需的索引,第一个索引如下:

blue_tables = results.find_all("div", "blue-box-wrap")
blue_tables[0]

他们没有ID,但他们有类。你可以做:

results.find_all("div", "blue-box-wrap")
其中
蓝框包装
是一个类

它将返回长度为22的
ResultSet
对象,因为有22个蓝色表格。您可以通过索引选择所需的索引,第一个索引如下:

blue_tables = results.find_all("div", "blue-box-wrap")
blue_tables[0]
替换:

 results = soup.find(id='ch_divSimple')
 mychk = results.prettify()
 tbl_elems = results.find_all('section', class_='wrap-verbs-listing')
与:

results = soup.find("div", attrs={"class": 'blue-box-wrap'})
tbl_elems = results.find_all('ul', class_='wrap-verbs-listing')
替换:

 results = soup.find(id='ch_divSimple')
 mychk = results.prettify()
 tbl_elems = results.find_all('section', class_='wrap-verbs-listing')
与:

results = soup.find("div", attrs={"class": 'blue-box-wrap'})
tbl_elems = results.find_all('ul', class_='wrap-verbs-listing')