代码
import requests
import string
from bs4 import BeautifulSoup
headers ={"User-Agent":"xxx"}
url="xxx"
response=requests.get(url,headers=headers)
print(response.status_code)
contrnt=response.text
##rint (contrnt)
soup=BeautifulSoup(contrnt,"html.parser")
ret_pl2=soup.findAll("div" ,attrs={"class":"pl2"})
##print(ret_pl2)
result=[]
for p12 in ret_pl2:
ret = p12.findAll("a", attrs={"class": ""})
for re in ret:
print(re)
##print(re.string)
打印结果
<a class="" href="https://xx.com/subject/35426925/">
想要提取的文字
/ <span style="font-size:13px;">不想要的文字</span>
</a>
用 print(re.string) 打印的结果是 None
我就想提取我想要的文字 应该用什么方法获取
我自己感觉就是现在标签里面有2处文字 他不知道获取哪个了 就打印的 “None” 求解答