繁体   English   中英

无法在python中用漂亮的汤来抓取数据

[英]Unable to scrape data with beautiful soup in python

这是我想刮的代码

<li id="shortlink">
<strong>Short link:</strong>
<input id="short-link-input" type="text" value="http://tnydu.biz/DfBCAEk" onclick="dbzglobal_event_adapter();">
</li>

我正在使用的脚本是这样的:

 shortlink=soup.select("#short-link-input value")
    
            print shortlink

但它给出了 [] 输出,我无法提取它的链接。 可用的方法是查找和选择。 有人可以帮忙吗

尝试这个

elem = soup.find('input',{'id':'short-link-input'})
print elem.get('value')

尝试这个:

shortlink=soup.select("#short-link-input")[0]['value']

select -method 返回元素列表。 要获取属性的值,您必须调用它的get -method 或使用属性的名称作为 key-index

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM