I'm trying to extract some informations from a website, but I don't know how to scrape the email.
This code works for me :
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup
url = "https://www.eurocham-cambodia.org/member/476/2-LEau-Protection"
uClient = uReq(url)
page_html = uClient.read()
uClient.close()
soup = BeautifulSoup(page_html,"lxml")
members = soup.findAll("b")
for member in members:
member = members[0].text
print(member)
I wanted to extract the number and link with soup.findAll() but can't find a way to get the text properly so I used the SelectorGadget tool and tried this :
numbers = soup.select("#content li:nth-child(1)")
for number in numbers:
number = numbers[0].text
print(number)
links = soup.findAll(".icon-globe+ a")
for link in links:
link = links[0].text
print(link)
It prints correctly :
2 L'Eau Protection
(+33) 02 98 19 43 86
http://www.2leau-protection.com/
Now, when it comes to extract the email address i'm stuck. I'm new to this, any advice would be appreciate, thank you!
Attempt 1
emails = soup.select("#content li:nth-child(2)")
for email in emails:
email = emails[0].text
print(email)
I don't even know what it just prints
//<![CDATA[
var l=new Array();
l[0]='>';l[1]='a';l[2]='/';l[3]='<';l[4]='|109';l[5]='|111';l[6]='|99';l[7]='|46';l[8]='|110';l[9]='|111';l[10]='|105';l[11]='|116';l[12]='|99';l[13]='|101';l[14]='|116';l[15]='|111';l[16]='|114';l[17]='|112';l[18]='|45';l[19]='|117';l[20]='|97';l[21]='|101';l[22]='|108';l[23]='|50';l[24]='|64';l[25]='|110';l[26]='|111';l[27]='|105';l[28]='|116';l[29]='|97';l[30]='|109';l[31]='|114';l[32]='|111';l[33]='|102';l[34]='|110';l[35]='|105';l[36]='|32';l[37]='>';l[38]='"';l[39]='|109';l[40]='|111';l[41]='|99';l[42]='|46';l[43]='|110';l[44]='|111';l[45]='|105';l[46]='|116';l[47]='|99';l[48]='|101';l[49]='|116';l[50]='|111';l[51]='|114';l[52]='|112';l[53]='|45';l[54]='|117';l[55]='|97';l[56]='|101';l[57]='|108';l[58]='|50';l[59]='|64';l[60]='|110';l[61]='|111';l[62]='|105';l[63]='|116';l[64]='|97';l[65]='|109';l[66]='|114';l[67]='|111';l[68]='|102';l[69]='|110';l[70]='|105';l[71]='|32';l[72]=':';l[73]='o';l[74]='t';l[75]='l';l[76]='i';l[77]='a';l[78]='m';l[79]='"';l[80]='=';l[81]='f';l[82]='e';l[83]='r';l[84]='h';l[85]=' ';l[86]='a';l[87]='<';
for (var i = l.length-1; i >= 0; i=i-1){
if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
else document.write(unescape(l[i]));}
//]]>
Attempt 2
emails = soup.select(".icon-mail~ a") #follow the same logic
for email in emails:
email = emails[0].text
print(email)
Error
NameError: name 'email' is not defined
Attempt 3
emails = soup.select(".icon-mail~ a")
print(emails)
Print empty
[]
Attempt 4,5,6
email = soup.find("a",{"href":"mailto:"}) # Print "None"
email = soup.findAll("a",{"href":"mailto:"}) # Print empty "[]"
email = soup.select("a",{"href":"mailto:"}) # Print a lot of informations but not the one that I need.