BeautifulSoup4:仅获取3行数据,而不是12行

罗克珊

我试图从“中”中抓取故事标题的数量,但这只是给我提供了前三名。但是有12-13。为什么?

这是我的代码:

from bs4 import BeautifulSoup
import requests as req

resp = req.get('https://medium.com/@daranept27')

soup = BeautifulSoup(resp.text, 'lxml')

x = soup.select('A.eg.bv')
print(x)

我正在使用css selector它,因为XPATH刮擦每个标题对我来说似乎很痛苦...我不想使用selenium,但是我很想知道您是否有理由不起作用:)

苏希尔

尝试使用requests_htmlasrequests_html可以在不使用的情况下抓取动态内容webdriver这是执行此操作的完整代码:

from requests_html import HTMLSession

session = HTMLSession()
r = session.get('https://medium.com/@daranept27')
r.html.render()

x = r.html.find('a.eg.bv')
[print(elem.text) for elem in x]

输出:

Seven Days -Between Life And Death
Have you ever encountered a fake friend? If So, Try These Simple Tips To Overcome it.
Does Anybody Ever Wonder Why He’s My Everything?
Ladies, Why Should You Treat Your Face Like The Coloring Books?
Listen, Girl, Aren’t You Curious How The Last Line Could Be This Hurtful?
The girl name “Rich”
She Lost Her Beloved Mother, But Why She Asserted that Loss Was Not Just A Loss sometimes?
You Used To Try This Lonely. Have You Ever Imagine The flavor You Tried To Eat it with Your Lover?
If You Have Siblings, You Won’t Comprehend this. Have You Ever Wonder How A Child Feels Like? This Is How It Perceives.
Is It Okay To Help A Stranger?
The Nightmare Was Always Considered A Bad Omen, But It Turned Incredible Differently.
If You’re A Woman Or Girl Who Loves To Wear Lipstick, Read This Poetry.
She Wants To Spread This Poetry For Every Girl Or Woman That Was Born Just Like The Way She Was.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章