我尝试从输入字段中提取一个值,使用漂亮的soup。我已经尝试了我所知道的一切,但总是一无所获
我尝试过使用.text、.content和get_text()方法属性,但仍然不起作用
results = requests.post(URL, data=payload_dict);
soup = BeautifulSoup(results.content, 'html.parser');
info = soup.find(class_='mandatory airport-complete');
print(info, end="-------\n")
print(info.attrs, end="-------\n")
print (info.value, end="-------\n")
print (info.contents, end="-------\n")
print (info.get_text(), end="-------\n")
实际输出:
<input class="mandatory airport-complete" data-complete-min-length="4" id="segments0departCity" name="searchAir.segments[0].departCity" onfocus="departCityFocus(this)" preferredcountry="NZ" title="Enter the departure city" type="text" value="Luang Prabang (LPQ)"> </input>"-------
{'type': 'text', 'id': 'segments0departCity', 'name': 'searchAir.segments[0].departCity', 'value': 'Luang Prabang (LPQ)', 'onfocus': 'departCityFocus(this)', 'title': 'Enter the departure city', 'data-complete-min-length': '4', 'preferredcountry': 'NZ', 'class': ['mandatory', 'airport-complete']}-------
None-------
[' ']-------
期望值:
"Luang Prabang (LPQ)"
实际上,我只对LPQ代码感兴趣,但可以通过尝试regex中的一些模式来接受整个值
截图的代码和输出转储从jupyter笔记本..因为这个网站似乎弄乱了一些格式。 p from juu
'value': 'Luang Prabang (LPQ)',
是在你的info.attrs
字典里吗?输入是info.attrs['value']
,如果我读对了你的输出相关问题 更多 >
编程相关推荐