python - scrape data and sort it using Python 2.7 and selenium
问题描述
i'm trying to scrape data in a website using selenium and python 2.7. Here is the code from the data that i want to scrape
<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>
i need to insert all that words to list and sort it. for now this is my progres
wordlist = []
data = browser.find_element_by_tag_name("textarea")
words = data.get_attribute()
wordlist.append(words)
print words
print wordlist.sort()
any help or clue would be useful for me
解决方案
请注意,wordlist.sort()
它不会返回list,而只是对已存在的 list 进行排序,因此您可能需要这样做
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,']
推荐阅读
- javascript - 将“C:\fakepath\”替换为“\\server\folder\”
- python - 是否可以在同一台计算机上同时运行 python 32 位和 64 位?以及在终端调用python时如何区分它们?
- visual-studio-code - >= 变成 > 带下划线
- firebase - 不受限制的 Firebase 密钥可用于其他付费 Google API
- kotlin -
- mysql - MySQL简单触发器在另一个表中找不到列
- java - 如果文本长度大于按钮大小,则 JButton 文本被截断
- ios - 集合视图按钮背景图像在滚动时重复
- r - 数据集中的“异常值”
- git - 在变基时保留历史中的提交