python-3.x - 从 Python 中的锚标记自动获取数据
问题描述
我有一个页面,内容如下
<div class="entry">
<p>some content></p>
<a href="www.somelink.com">more</a>
</div>
在主网页中。我想在单击链接时提取并显示数据。我在python3中使用beautifulsoup。
解决方案
mainpage
您可以使用参数显示提取的url的内容。
code = '''<div class="entry">
<p>some content></p>
<a href="www.somelink.com">more</a>
</div>'''
soup = BeautifulSoup(code, 'html.parser')
divtag = soup.find('div', attrs={"class": "entry"})
a_tags = divtag.find_all('a')
for a in a_tags:
url = a.get('href')
response = requests.get(url)
mainpage = BeautifulSoup(response.text, 'html5lib')
推荐阅读
- r - Reticulate 找不到 Anaconda 安装
- swift - 如何使 CAshapeLayer 适合按钮?
- javascript - 我可以使用哪种图表来使用 ChartJS(或类似的)来实现这一点?
- c++ - 如何完全禁用 qtableview 的选择(对于所有单元格)?
- firebase - 想要在默认的 android 抽屉上打印电子邮件但收到一些“Closure()”错误
- swift - 绑定更改后未重新评估 SwiftUI 主体
- flutter - 颤动的粘性标题列表在滚动时添加项目
- nginx - NGINX 根据位置值重定向到代理(代理通行证)
- javascript - Kendo Treeview 从 dataBound 获取值
- css - CSS 径向渐变规则适用于除 Firefox 之外的所有浏览器