Issue
In Python/BeautifulSoup, below code title
values is
<span class="ux-textspans"><!--F#f_7[0]-->4K Photon MONO<!--F/--></span>
when use title.get_text()
to get text 4K Photon MONO
, it failed .Any can help ? Thanks!
import requests
from bs4 import BeautifulSoup
url='https://www.ebay.com/itm/284163810059'
req=requests.get(url)
soup=BeautifulSoup(req.text,'lxml')
title=soup.select('div > div:nth-child(2) > div:nth-child(4) > div > span > div > span')
title_text= title.get_text()
Solution
It can also be done using soup.find
function.
import requests
from bs4 import BeautifulSoup
url='https://www.ebay.com/itm/284163810059'
req=requests.get(url)
soup=BeautifulSoup(req.text,'lxml')
title=soup.find("span", {"itemprop" : "model"})
title_text= "" if title is None else title.get_text()
Answered By - ZeroOne
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.