gpt4 book ai didi

python - 使用 Python 2.7 和 selenium 抓取数据并对其进行排序

转载 作者:太空宇宙 更新时间:2023-11-04 04:24:05 27 4
gpt4 key购买 nike

我正在尝试使用 selenium 和 python 2.7 抓取网站中的数据。这是我要抓取的数据中的代码

<textarea>let, either, and, have, rather, because, your, with, other, that, neither, since, however, its, will, some, own, than, should, wants, they, got, may, what, least, else, cannot, like, whom, which, who, why, his, these, been, had, the, all, likely, their, must, our</textarea>

我需要插入所有这些词来列出和排序它。现在这是我的进步

wordlist = []
data = browser.find_element_by_tag_name("textarea")
words = data.get_attribute()
wordlist.append(words)
print words
print wordlist.sort()

任何帮助或线索都会对我有用

最佳答案

请注意,wordlist.sort() 不会返回列表,而只是对现有列表进行排序,因此您可能需要做/p>

wordlist.sort()
print wordlist

或尝试以下代码以获得所需的输出

data = driver.find_element_by_tag_name("textarea")
words = data.get_attribute('value')
sorted_list = sorted(words.split(', '))
print sorted_list
# ['all,', 'and,', 'because,', 'been,', 'cannot,', 'either,', 'else,', 'got,', 'had,', 'have,', 'his,', 'however,', 'its,', 'least,', 'let,', 'like,', 'likely,', 'may,', 'must,', 'neither,', 'other,', 'our', 'own,', 'rather,', 'should,', 'since,', 'some,', 'than,', 'that,', 'the,', 'their,', 'these,', 'they,', 'wants,', 'what,', 'which,', 'who,', 'whom,', 'why,', 'will,', 'with,', 'your,']

关于python - 使用 Python 2.7 和 selenium 抓取数据并对其进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53848926/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com