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

标签 python web-scraping selenium-chromedriver

我正在尝试使用 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/

相关文章:

python - Many2one Odoo 11 中的域

selenium-chromedriver - 安装 chromedriver 时,URLResourceKey.quarantinePropertiesKey 仅在 OS X 10.10 或更高版本上可用

c# - driver.Close 后如何从 ChromeDriver 重新打开浏览器?

python - C 到 Python 代码转换(打印类似地址的值)

Python线程: Threads runs twice?

ruby - 访问 div 元素数组中的 div 元素的属性

python - 在Python中抓取<table>TABLE I NEED</table>之间的所有文本

javascript - 从脚本中的 var 中提取数据并使用 python 将 pdf 下载到文件夹

java - 配置失败 : @BeforeMethod setup org. openqa.selenium.NoSuchSessionException : Session ID is null. 调用 quit() 后使用 WebDriver?

python - 从 Golang 调用 Python 任务