BeautifulSoup python:获取没有标签的文本并获取相邻的链接 [英] BeautifulSoup python: Get the text with no tags and get the adjacent links

查看:140
本文介绍了BeautifulSoup python:获取没有标签的文本并获取相邻的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从此网站

from bs4 import BeautifulSoup
from requests import get


link = "https://tamilrockerrs.ch"
r = get(link).content
#r = open('json.html','rb').read()
b = BeautifulSoup(r,'html5lib')
a = b.findAll('p')[1]

但是问题是标题没有标签.我无法提取标题,如果可以的话,如何将链接和标题绑定在一起.

But the problem is there is no tag for the titles. I can't extract the titles and if I could do that how can I bind the links and title together.

预先感谢

推荐答案

您可以通过这种方式找到titlelink.

You can find title and link by this way.

from bs4 import BeautifulSoup
import requests    

url= "http://tamilrockerrs.ch"

response= requests.get(url)

data = response.text

soup = BeautifulSoup(data, 'html.parser')

data = soup.find_all('div', {"class":"title"})

for film in data:
    print("Title:", film.find('a').text) # get the title here 
    print("Link:",  film.find('a').get("href")) #get the link here 

这篇关于BeautifulSoup python:获取没有标签的文本并获取相邻的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆