如何网络抓取元内容 - Python 网络抓取问题
我只想刮掉“汽车”一词,而不是带有元括号的整行。
所需的输出:“汽车”
你能告诉我如何解决这个问题吗?谢谢!
from bs4 import BeautifulSoup
import requests
import csv
URL = 'https://www.electrive.com/2022/02/13/skoda-reveals-uk-pricing-for-enyaq-coupe-iv-vrs/'
(response := requests.get(URL)).raise_for_status()
soup = BeautifulSoup(response.text, 'lxml')
category2 = soup.find('meta', property='article:section')
print(category2)
输出:
<meta content="Automobile" property="article:section"/>
I want to only scrape the word "Automobile" not the entire line with the meta brackets.
Desired output: "Automobile"
Can you please tell me how to fix this? Thanks!
from bs4 import BeautifulSoup
import requests
import csv
URL = 'https://www.electrive.com/2022/02/13/skoda-reveals-uk-pricing-for-enyaq-coupe-iv-vrs/'
(response := requests.get(URL)).raise_for_status()
soup = BeautifulSoup(response.text, 'lxml')
category2 = soup.find('meta', property='article:section')
print(category2)
Output:
<meta content="Automobile" property="article:section"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将
['content']
添加到您的soup
对象即可。输出:
Just add
['content']
to yoursoup
object.Output: