【问题标题】:selenium python find elements output to pandasselenium python查找输出到熊猫的元素
【发布时间】:2021-07-27 06:03:24
【问题描述】:

这里是新手。

Selenium Python, Find Elements, Pandas: 上需要帮助

代码如下:

array=[]
array=driver.find_elements_by_xpath("//fl-list-item")
for e in array:
   print(e.text)

我可以看到打印(e.text)如下:(有20个元素,这是第一个)

Convert a PDF in Word
$250 – 750 USD
Posted 6 minutes ago
We would like to have a (scanned) PDF file convert to a Word file
Data Entry
Excel
PDF
Word
Copy Typing
Fixed Price
28 Bids
0.0

问题:如何使用 Pandas 将这些作为带有标题的一行?

看了很多视频,了解了一些点点滴滴,但无法将数据输入 Pandas。

在这里感谢对新手的帮助。

【问题讨论】:

    标签: python pandas selenium


    【解决方案1】:

    据我了解,您希望将每个数组项存储在单独的列中,并在 for 循环中为其提供标题。您可以这样做:

    import pandas as pd
    
    # create a dataframe with correct shape
    df = pd.DataFrame({'index':['placeholder']})
    
    # your array here
    array = ['first','second','third','fourth']
    
    # create an index for column headers
    index = 1
    
    # iterate through your array and set each column value
    for item in array:
        df[index] = item
        index += 1
    
    print(df.head())
    

    输出:

             index      1       2      3       4
    0  placeholder  first  second  third  fourth
    

    【讨论】:

    • 感谢Geom!它确实将我拥有的数组放入 pandas 并产生了您所指示的输出。猜猜我的下一个问题是将每个元素的内容提取到列中。将看看我是否可以发布输出图片以获得更好的说明。哦,看来我不能发截图了。
    • 现在 pandas 索引 1 正在存储数组的第一个元素。就是这样,我需要每行数据位于单独的列中,即一行转换为一列。如果 pandas 可以轻松做到这一点,请欣赏指导(指向学习视频对我来说是完美的)。在 Word 中转换 PDF 250 美元 – 750 美元 6 分钟前发布 我们希望将(扫描的)PDF 文件转换为 Word 文件 数据输入 Excel PDF Word 复制 打字 固定价格 28 出价 0.0
    猜你喜欢
    • 2019-01-08
    • 2019-01-26
    • 2021-12-17
    • 2018-11-07
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多