【发布时间】:2021-03-20 06:26:16
【问题描述】:
我正在从如下下拉菜单中抓取链接(前后有一堆东西)
<li class="selectyear">
<select id="years">
<option selected="" value="/linkfor2020" "="">2020 Name
<option value="/linkfor2010" "="">2010 Name
<option value="/linkfor2009" "="">2009 Name
</select>
<button class="selectyear" aria-label="Choose Year">Go</button>
</li>
我的代码如下:
with open("data.html") as fp:
soup = BeautifulSoup(fp, "html.parser")
yearlist = soup.find("option",value=True)
for item in yearlist.find_all('option'):
value=item.get('value')
print value
但是,它没有获取 2020 链接。输出只是后两个。为什么第一个选项被忽略了?
【问题讨论】:
标签: beautifulsoup