如何从gmail API的邮件中提取PHP中html中的数据?

时间:2019-02-13 17:22:11

标签: php html email gmail-api

  • 我从GMAIL API检索电子邮件。
  • 我有每封邮件的内容。
  • 我必须在此html中提取一些内容。但是此html充满了表格,选择器没有任何ID或类。

<html>
	<head>
		<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8">
			<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=3D=  1.0">
				<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=3D=  1, maximum-scale=3D1">
				</head>
				<body style=3D"font-family: 'Source Sans Pro',sans-serif;background-color: =  #dfdfdf;padding: 15px;margin: 0;font-size: 1px;mso-line-height-alt: 0;line-=  height: 0;mso-margin-top-alt: 1px;">
					<table style=3D"border-collapse: collapse;color: #5a5a5a;font-size: 14px;=  -ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;width: 100%">
						<tr style=3D"font-size: 14px;line-height: 21px;text-align: left;vertica=  l-align: top;">
							<td></td>
							<td style=3D"color: #5a5a5a;font-size: 14px;line-height: 21px;text-al=  ign: left;vertical-align: top;width: 960px;min-width: 520px;border: 1px sol=  id #5a5a5a;padding: 20px;background: #ffffff;">
								<table style=3D"border-collapse: collapse;">
									<tr style=3D"font-size: 14px;line-height: 21px;text-align: left;v=  ertical-align: top;">
										<td style=3D"color: #5a5a5a;font-size: 14px;line-height: 21px;v=  ertical-align: middle;">
											<table style=3D"border-collapse: collapse;width: 100%;border-=  bottom: 2px solid #ebebeb;">
												<tr>
													<td style=3D"height: 82px;text-align: center;vertical-ali=  gn: middle;font-weight: 300;font-size:32px;padding-bottom:16px;font-family:=   'Source Sans Pro',sans-serif;color: #5a5a5a;">                      Email Archive Status Report                    </td>
												</tr>
											</table>
											<table style=3D"border-collapse: collapse;line-height: 21px;t=  ext-align: left;vertical-align: top;height: auto;margin: 0 20px 20px 0;">
												<tr style=3D"font-size: 14px;line-height: 21px;text-align: =  left;vertical-align: top;">
													<td style=3D"color: #5a5a5a;font-size: 14px;line-height: =  21px;text-align: left;vertical-align: top;">
														<table style=3D"border-collapse: collapse;font-size: 14=  px;margin: 10px 10px 0 10px;width: 100%;">
															<tr style=3D"font-size: 14px;vertical-align: top;">
																<td style=3D"color: #5a5a5a;font-family: 'Source Sa=  ns Pro',sans-serif;font-size: 14px;line-height: 21px;text-align: left;verti=  cal-align: top;width: 50%;margin-right: 10px;">
																	<div style=3D"color: #e65f1e;border-bottom: 1px s=  olid #ebebeb;font-size: 18px;padding: 0 3px 0 3px;margin-bottom: 4px;line-h=  eight: 36px;height: 30px;margin-right: 20px;">License</div>
																	<table style=3D"border-collapse: collapse;">
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Archives</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">7 archives</td>
																		</tr>
																	</table>
																</td>
																<td style=3D"color: #5a5a5a;font-family: 'Source Sa=  ns Pro',sans-serif;font-size: 14px;line-height: 21px;text-align: left;verti=  cal-align: top;width: 50%;margin-left: 10px;">
																	<div style=3D"color: #e65f1e;border-bottom: 1px s=  olid #ebebeb;font-size: 18px;padding: 0 3px 0 3px;margin-bottom: 4px;line-h=  eight: 36px;height: 30px;margin-right: 20px;">Instance</div>
																	<table style=3D"border-collapse: collapse;">
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Instance Name</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">k477931430</td>
																		</tr>
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Version</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">11.2.1.14113 (64-bit; Build Date 1/=  14/2019)</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>
														<table style=3D"border-collapse: collapse;font-size: 14=  px;margin: 10px 10px 0 10px;width: 100%;">
															<tr style=3D"font-size: 14px;vertical-align: top;">
																<td style=3D"color: #5a5a5a;font-family: 'Source Sa=  ns Pro',sans-serif;font-size: 14px;line-height: 21px;text-align: left;verti=  cal-align: top;width: 50%;margin-right: 10px;">
																	<div style=3D"color: #e65f1e;border-bottom: 1px s=  olid #ebebeb;font-size: 18px;padding: 0 3px 0 3px;margin-bottom: 4px;line-h=  eight: 36px;height: 30px;margin-right: 20px;">Archive</div>
																	<table style=3D"border-collapse: collapse;">
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Total Size</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">538,782 messages</td>
																		</tr>
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Newly Archived 
																				<span style=3D"font-s=  ize: 10px;">(2/12/2019)</span>
																			</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">276 messages</td>
																		</tr>
																	</table>
																</td>
																<td style=3D"color: #5a5a5a;font-family: 'Source Sa=  ns Pro',sans-serif;font-size: 14px;line-height: 21px;text-align: left;verti=  cal-align: top;width: 50%;margin-left: 10px;">
																	<div style=3D"color: #e65f1e;border-bottom: 1px s=  olid #ebebeb;font-size: 18px;padding: 0 3px 0 3px;margin-bottom: 4px;line-h=  eight: 36px;height: 30px;margin-right: 20px;">Compliance</div>
																	<table style=3D"border-collapse: collapse;">
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Service Provider Access</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">Enabled</td>
																		</tr>
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Archive Access by Admin</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">Enabled</td>
																		</tr>
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Retention Policies</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">Total: 0 / Enabled: 0 / Automatic D=  eletion: 0</td>
																		</tr>
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Legal Hold</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">Disabled</td>
																		</tr>
																		<tr style=3D"font-size: 14px;vertical-align: to=  p;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;max-width: 270px;overflow: hidden;whi=  te-space: nowrap;padding-right: 50px;">Auditing</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;text-align: left;vertical-align: t=  op;line-height: 21px;padding-bottom:0;">17 event types of 28</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>
														<table style=3D"border-collapse: collapse;font-size: 14=  px;margin: 10px 10px 0 10px;width: 100%;">
															<tr style=3D"font-size: 14px;line-height: 21px;text-a=  lign: left;vertical-align: top;">
																<td style=3D"color: #5a5a5a;font-family: 'Source Sa=  ns Pro',sans-serif;font-size: 14px;line-height: 21px;text-align: left;verti=  cal-align: top;">
																	<div style=3D"color: #e65f1e;border-bottom: 1px s=  olid #ebebeb;font-size: 18px;padding: 0 3px 0 3px;margin-bottom: 4px;line-h=  eight: 36px;height: 30px;">                              Archiving Statistics 
																		<span style=3D"font-size: =  12px;">(2/12/2019)</span>
																	</div>
																	<table style=3D"border-collapse: collapse;width: =  100%;">
																		<tr style=3D"vertical-align: top;mso-line-heigh=  t-alt: 22px;line-height: 22px;">
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: left;width: 48%;">Name</th>
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: right;width: 11%;">Successful</th>
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: right;width: 11%;">Failed</th>
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: left;width: 19%;">Last Execution</th>
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: center;width: 11%;">Last Result</th>
																		</tr>
																		<tr style=3D"font-size: 14px;text-align: left;l=  ine-height: 21px;vertical-align: top;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">vachonsecure.fr Charles</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">210</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">0</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">2/12/2019 11:53:42 PM</td>
																			<td style=3D"font-weight: bold;color: green;f=  ont-family: 'Source Sans Pro',sans-serif;font-size: 14px;line-height: 21px;=  vertical-align: top;text-align: center;padding: 0 8px;">Succeeded</td>
																		</tr>
																		<tr style=3D"font-size: 14px;text-align: left;l=  ine-height: 21px;vertical-align: top;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">bs-technology.fr Eric</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">133</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">0</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">2/12/2019 11:48:20 PM</td>
																			<td style=3D"font-weight: bold;color: green;f=  ont-family: 'Source Sans Pro',sans-serif;font-size: 14px;line-height: 21px;=  vertical-align: top;text-align: center;padding: 0 8px;">Succeeded</td>
																		</tr>
																		<tr style=3D"font-size: 14px;text-align: left;l=  ine-height: 21px;vertical-align: top;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">boxalacarte.com Eric</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">244</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">0</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">2/12/2019 11:53:42 PM</td>
																			<td style=3D"font-weight: bold;color: green;f=  ont-family: 'Source Sans Pro',sans-serif;font-size: 14px;line-height: 21px;=  vertical-align: top;text-align: center;padding: 0 8px;">Succeeded</td>
																		</tr>
																		<tr style=3D"font-size: 14px;text-align: left;l=  ine-height: 21px;vertical-align: top;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">pascapascal.bovero
																				<img style=3D"dis=  play: none;" />@uniic.org
																			</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">161</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">0</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">2/12/2019 11:54:10 PM</td>
																			<td style=3D"font-weight: bold;color: green;f=  ont-family: 'Source Sans Pro',sans-serif;font-size: 14px;line-height: 21px;=  vertical-align: top;text-align: center;padding: 0 8px;">Succeeded</td>
																		</tr>
																		<tr style=3D"font-size: 14px;text-align: left;l=  ine-height: 21px;vertical-align: top;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">bs-technology.fr Info</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">265</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">0</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">2/12/2019 11:59:03 PM</td>
																			<td style=3D"font-weight: bold;color: green;f=  ont-family: 'Source Sans Pro',sans-serif;font-size: 14px;line-height: 21px;=  vertical-align: top;text-align: center;padding: 0 8px;">Succeeded</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>
														<table style=3D"border-collapse: collapse;font-size: 14=  px;margin: 10px 10px 0 10px;width: 100%;">
															<tr style=3D"font-size: 14px;line-height: 21px;text-a=  lign: left;vertical-align: top;">
																<td style=3D"color: #5a5a5a;font-family: 'Source Sa=  ns Pro',sans-serif;font-size: 14px;line-height: 21px;text-align: left;verti=  cal-align: top;">
																	<div style=3D"color: #e65f1e;border-bottom: 1px s=  olid #ebebeb;font-size: 18px;padding: 0 3px 0 3px;margin-bottom: 4px;line-h=  eight: 36px;height: 30px;">                              Jobs 
																		<span style=3D"font-size: 12px;">(2/12/201=  9)</span>
																	</div>
																	<table style=3D"border-collapse: collapse;">
																		<tr style=3D"color: #5a5a5a;font-family: 'Sourc=  e Sans Pro',sans-serif;font-size: 14px;text-align: left;line-height: 21px;v=  ertical-align: top;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;text-align: left;vertical-align: top;font-size: 12=  px;line-height: 16px;padding-bottom: 10px;">
																				<b>Important Notice:</b> The last result on=  ly represents the status of the job execution itself but does not necessari=  ly correspond to the result of the command executed by this job. To access =  the output of the executed command, go to 
																				<em>Administrative Tools &gt; Man=  agement API &gt; Job Results</em> in the client and double-click on the res=  pective entry.                                
																			</td>
																		</tr>
																	</table>
																	<table style=3D"border-collapse: collapse;width: =  100%;">
																		<tr style=3D"vertical-align: top;mso-line-heigh=  t-alt: 22px;line-height: 22px;">
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: left;width: 48%;">Name</th>
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: right;width: 11%;">Successful</th>
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: right;width: 11%;">Failed</th>
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: left;width: 19%;">Last Execution</th>
																			<th style=3D"font-size: 14px;vertical-align: =  top;font-family: 'Source Sans Pro',sans-serif;line-height: normal;padding: =  4px 8px;white-space: nowrap;background-color: #505050;color: #ffffff;font-w=  eight: normal;text-align: center;width: 11%;">Last Result</th>
																		</tr>
																		<tr style=3D"font-size: 14px;text-align: left;l=  ine-height: 21px;vertical-align: top;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">Envoyer le rapport de statut</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">1</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">0</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">2/12/2019 5:30:02 AM</td>
																			<td style=3D"font-weight: bold;color: green;f=  ont-family: 'Source Sans Pro',sans-serif;font-size: 14px;line-height: 21px;=  vertical-align: top;text-align: center;padding: 0 8px;">Succeeded</td>
																		</tr>
																		<tr style=3D"font-size: 14px;text-align: left;l=  ine-height: 21px;vertical-align: top;">
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">Process Retention Policies</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">1</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: right;padding: 1px 8px;">0</td>
																			<td style=3D"color: #5a5a5a;font-family: 'Sou=  rce Sans Pro',sans-serif;font-size: 14px;line-height: 21px;vertical-align: =  top;text-align: left;padding: 1px 8px;">2/12/2019 3:30:00 AM</td>
																			<td style=3D"font-weight: bold;color: green;f=  ont-family: 'Source Sans Pro',sans-serif;font-size: 14px;line-height: 21px;=  vertical-align: top;text-align: center;padding: 0 8px;">Succeeded</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>
													</td>
												</tr>
											</table>
											<div style=3D"height: 30px;border-top: 1px solid #e5e5e5;marg=  in: 5px;color: #999999;mso-line-height-alt: 18px;mso-margin-top-alt: 18px;l=  ine-height: 18px;font-size: 11px;">
												<div style=3D"text-align: left;">
													<span style=3D"font-size: 11px;mso-line-height-alt: 18px;=  line-height: 18px;mso-margin-top-alt: 18px;color: #5a5a5a;text-align: left;=  vertical-align: top;font-family: 'Source Sans Pro',sans-serif;">&nbsp;
													</spa=  n>
												</div>
											</div>
										</td>
									</tr>
								</table>
							</td>
							<td></td>
						</tr>
					</table>
				</body>

在此字符串中,我想提取一些数据,例如电子邮件和日期。这不是这里最复杂的事情。所有邮件地址都不像

"johndoe@gmail.com"

可以,但是大多数邮件地址都像

xxx.fr Charles

首先,我尝试提取html,然后使用XPath检索所需的内容。但是问题是当我仅选择“ // tr”时,如何知道哪个字符串是地址,另一个字符串是位置还是其他什么

这是我的代码:

            $message_id = $lm->id;
            $thread_id = $lm->threadId;
            $optParamsGet2['format'] = 'raw';
            $single_message = $gmail->users_messages->get('me', $message_id, $optParamsGet2);
            $body = base64url_decode($single_message->raw);
            $string = preg_replace('~[[:cntrl:]]~', " ", $body);
            $rawString = strip_tags(preg_replace('/\s+/', '', $string));

            $html = get_string_between($string, "<!DOCTYPE html>", "</html>");

            libxml_use_internal_errors(true) AND libxml_clear_errors();
            $doc = new DOMDocument();
            $doc->preserveWhiteSpace = false;
            $doc->loadHTML($html);

            $xpath = new DOMXpath($doc);
            $nodes = $xpath->query("//tr");

您有一些建议吗?

编辑:

我尝试了@Anthony Harley的解决方案,这是结果link。我使用正则表达式提取开始,但对于地址,我无法。在表的索引10中,我要提取名称,日期以及是否成功。但是每个用户的模式都不相同。

2 个答案:

答案 0 :(得分:0)

我已根据我们的评论链对您的脚本进行了一些更改。您肯定会更轻松地将其保留为DOMDocument。但是,您并没有将电子邮件转换为带引号的printable,这可能就是您使用DomXPath的原因。下面的代码从表中打印5条记录,该模式可用于从任何其他表中获取数据。此时,如何处理该字段中的电子邮件将取决于您。希望这会有所帮助!

<?php

$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$file = quoted_printable_decode(file_get_contents('test.html'));
$doc->loadHTML($file);

$records = [];

$tables = $doc->getElementsByTagName('table');
$emailTable = $tables->item(10);

$rows = $emailTable->getElementsByTagName('tr');

for($i = 2; $i < $rows->length; $i++) {
    $row = $rows->item($i);
    $cells = $row->getElementsByTagName('td');

    $records[] = [
        'Email' => $cells->item(0)->nodeValue
    ];
}

var_dump($records);
?>

答案 1 :(得分:-1)

您应该为此使用数组,因为它们简单明了。 我将举一个示例,以便您可以使用它来创建自己的代码,因为该代码并不十分清楚,但是我仍然希望提供一个答案。

如果您不熟悉数组,我将解释数组的工作原理。

您可以这样创建一个数组:

    <?php
    $array = array(
   "variable1" => "someemail@address.com",
   "variable2" => "foo",
    );
    ?>

它们可以是整数或字符串。

要检索它,可以使用:

<?php
echo "Email:";
echo $variable1;
?>

我希望我能很好地解释基础知识,希望您可以使用它。