Python beautifulsoup how to get the line after href

2024/11/15 0:46:45

I have this piece of html:

<a href="http://francetv.fr/videos/alcaline_l_instant_,12163184.html"  class="ss-titre">"Paris Combo"                   </a>    
<a href="http://francetv.fr/videos/jt20h_,12185324.html" class="ss-titre"> Journal         </a>

I can get http://francetv.fr/videos/jt20h_,12185324.html (example, not the real adress) but now, I would like, using beautifulsoup, to get "Paris Combo", and "Journal". I tried this:

for line in soup.findAll('/a'):title = line.get('</a>')

How can I do? Thanks

Answer

You need to call find_all("a") instead.

>>> for line in soup.find_all("a"):
...     print(line.text.strip())
"Paris Combo"
Journal
https://en.xdnf.cn/q/119349.html

Related Q&A

Scrapy empty output

I am trying to use Scrapy to extract data from page. But I get an empty output. What is the problem? spider: class Ratemds(scrapy.Spider):name = ratemdsallowed_domains = [ratemds.com]custom_settings =…

nested classes - how to use function from parent class?

If I have this situation:class Foo(object):def __init__(self):self.bar = Bar()def do_something(self):print doing somethingclass Bar(object):def __init(self):self.a = adef some_function(self):I want to …

CUDA Function Wont Execute For Loop on Python with Numba

Im trying to run a simple update loop of a simulation on the GPU. Basically there are a bunch of "creatures" represented by circles that in each update loop will move and then there will be a…

Implementing the Ceaser Cipher function through input in Python

Im trying to create a Ceaser Cipher function in Python that shifts letters based off the input you put in.plainText = input("Secret message: ") shift = int(input("Shift: "))def caes…

Twitter scraping of older tweets

I am doing a project in which I needed to get tweets from twitter, and I used the twitter API but it only gives tweets from 7-9 days old but I want a few months older tweets as well. So I decided to sc…

Bootstrap Navbar Logo not found

Hello I am trying to get my NavBar on bootstrap to show a Logo, I have tried moving the png to different folders in the app but I get this error: System check identified no issues (0 silenced). January…

Why camelcase not installed?

i try to install camelcase in my python project. pip install camelcase but when i want to use the package, pylance give me this error: Import "camelcase" could not be resolved Pylance (report…

Find the two longest strings from a list || or the second longest list in PYTHON

Id like to know how i can find the two longest strings from a list(array) of strings or how to find the second longest string from a list. thanks

Which tensorflow-gpu version is compatible with Python 3.7.3

Actually, I am tired of getting "ImportError: DLL load failed" inWindows 10 CUDA Toolkit 10.0 (Sept 2018) Download cuDNN v7.6.0 (May 20, 2019) / v7.6.4 tensorflow-gpu==1.13.1 / 1.13.2 / 1.14 …

Find valid strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 6…