[英]How can I use the find all () and () txt methods in the BeautifulSoup library?
I want all tags with a bargain price from the link given to the url.我想要 url 的链接中的所有价格便宜的标签。 find.
寻找。 But when I use the find_all () method I use and want it as text ()
但是当我使用 find_all () 方法时,我使用并希望它作为 text ()
Show in the for loop, but I have the following output:在for循环中显示,但我有以下output:
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
my code:我的代码:
import requests
from bs4 import BeautifulSoup
import re
url = 'https://divar.ir/s/tehran/auto'
test_page = requests.get(url)
b = test_page.text
soup = BeautifulSoup(b,'html.parser')
c = soup.find_all('div',attrs="kt-post-card__top-description kt-post-card-description")
for v in c:
print(v.txt)
Please help me solve this problem请帮我解决这个问题
You can simply find all class attribute by using c = soup.find_all(class_="kt-post-card__top-description kt-post-card-description")
您可以使用
c = soup.find_all(class_="kt-post-card__top-description kt-post-card-description")
简单地找到所有 class 属性
The following code will get the result下面的代码会得到结果
import requests
from bs4 import BeautifulSoup
url = 'https://divar.ir/s/tehran/auto'
test_page = requests.get(url).text
soup = BeautifulSoup(test_page,'html.parser')
c = soup.find_all(class_="kt-post-card__top-description kt-post-card-description")
for i in c:
print(i.text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.