簡體   English   中英

工作失敗,沒有更多細節。 我使用了一個簡單的rdd.map,轉換為DF和show()

[英]Job failure with no more details. I used a simple rdd.map, convert to DF and show()

我是pyspark的超級乞丐。 只是嘗試一些代碼來處理Databricks社區中的文檔。 我在Dataframe中有很多html頁面,需要映射一個清除所有html標簽的函數。

from selectolax.parser import HTMLParser
def get_text_selectolax(html):
    tree = HTMLParser(html)
    if tree.body is None:
        return None
    for tag in tree.css('script'):
        tag.decompose()
    for tag in tree.css('style'):
        tag.decompose()
    for node in tree.css('body'):
      if node.tag == "strong":
        print( "node.html" )
        print( node.html )
    text = tree.body.text(separator='\n')
    return text

df_10 = df.limit(10) #Out: df_10:pyspark.sql.dataframe.DataFrame
rdd_10_2 = df_10.select("html").rdd.map( get_text_selectolax )
schema = StructType([
    StructField("html", StringType()),
])
df_10_2 = spark.createDataFrame(rdd_10_2, schema)
df_10_2.show() #-----------> here the code failure

我想清理所有文檔並使用Dataframe。 謝謝

這是完整的筆記本: https//databricks-prod-cloudfront.cloud.databricks.com/public/4027ec902e239c93eaaa8714f173bcfc/5506005740338231/939083865254574/8659136733442891/latest.html

我可以讓這個東西工作,但在scala中,對我來說什么都沒關系。

val version = "3.9.1"
val baseUrl = s"http://repo1.maven.org/maven2/edu/stanford/nlp/stanford-corenlp"
val model = s"stanford-corenlp-$version-models.jar" // 
val url = s"$baseUrl/$version/$model"
if (!sc.listJars().exists(jar => jar.contains(model))) {
  import scala.sys.process._
  // download model
  s"wget -N $url".!!
  // make model files available to driver
  s"jar xf $model".!!
  // add model to workers
  sc.addJar(model)
}

import org.apache.spark.sql.functions._
import com.databricks.spark.corenlp.functions._

val df_limpo = ds.select(cleanxml('html).as("acordao"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM