我正在尝试获取某个a
的文本,它住在一个div中的li中。类似:div -> ul -> li -> a
。但我没有达到这个目标。我可以打印第一项,当我将.find
更改为findAll
时,控制台返回一个错误:
"ResultSet object has no attribute `'%s'`. You're probably treating a list of items like a single item. Did you call `find_all()` when you meant to call `find()`?"
`% key` AttributeError: `ResultSet` object has no attribute 'text'. You're probably treating a list of items like a single item. Did you call `find_all()` when you meant to call `find()`?
我的代码到现在为止:
1 from urllib.request import urlopen
2 from bs4 import BeautifulSoup
3 import pandas as pd
4
5 url = "http://amoraosromances.blogspot.com/"
6 page = urlopen(url)
7 soup = BeautifulSoup(page, 'lxml')
8
9 for div in soup.findAll('div', class_='widget Label', id='Label2'):
10 a = div.findAll('a')
11 print(a.text)
如果您没有绑定到
beautifulsoup
,那么可以使用Selenium WebDriver
执行相同的操作我试过这段代码来得到你想要的
这使得输出像
如果您想为Chrome设置Selenium,可以使用这个link开始使用Selenium
相关问题 更多 >
编程相关推荐