![](/img/trans.png)
[英]using beautiful soup 4 to scrape weather data (site is coded in javascript)
[英]Unable to scrape some table using beautiful soup
我正在使用 BeautifulSoup 从网站链接中抓取数据。 共有 9 个表具有相同的 class 名称,但我只能获得链接 5 个表。 我应该在代码中做哪些更改,以便我可以从上面的链接中抓取所有存在的表格?
以下是我使用的代码:
def ScrapeSecScreen():
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Chrome("C:/Users/pralo/Downloads/DE/chromedriver", chrome_options=options)
driver.get('https://www.panamacompra.gob.pa/Inicio/v2/#!/vistaPreviaCP?NumLc=2022-0-30-0-08-CL-024792&esap=0&nnc=0&it=1')
sleep(10)
sourcecode = driver.execute_script("return document.getElementsByTagName('html')[0].innerHTML")
# print(sourcecode)
soup = BeautifulSoup(sourcecode,"html.parser")
print(soup)
l1 = []
tablelist1=soup.findAll('table',{'class':'table table-condensed table-bordered last-line-table'})
for tr in tablelist1:
td = tr.find_all('tr')
row = [tr.text for tr in td]
l1.append(row)
print(l1)
ScrapeSecScreen()
经检查,事实证明只有前五个表与您提到的类匹配。 要获取所有表,您可以省略 class 参数或指定所有表共享的 class。
检查这行代码:
soup.find_all('table', class_='table')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.