简体   繁体   中英

i am unable to scrape the phone number . Can anyone help me

Here is the html content of that part.

<p class="contact-info " onclick="_ct('clntphn', 'lspg');">
  <i class="contactNo spriteImg"></i>
  <span><a><b>+(91)-80-30805680</b></a></span>
</p>

I have tried extracting this by:

soup.find('p',{'class':'contact-info'})  

but in vain . It is unable to do the same.

You can use the find method with tag:

from bs4 import BeautifulSoup as soup
s = soup(html_data, "lxml")
number = s.find('b').text  

Output:

u'+(91)-80-30805680'

To get the first instance, you can try this:

new_s = s.findAll("p", {"class":"contact-info"})
new_data = [i.text for i in new_s]
print(new_data[0].replace("\n", ''))

Output:

+(91)-80-30805680

您需要将您的 find 方法加入链中:

soup.find('p',{'class':'contact-info'}).find('b').text

I would use a CSS selector. As there is some whitespace around it, we can easily strip it.

soup.select_one('p.contact-info').get_text(strip=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM