我的web scraper搜索返回不同数量的表行,我不习惯处理表。这些表各有3列。我检查一下第一栏的街道号码是否正确。如果是的话,那么我需要从该行的第三列中获取链接。有什么想法吗?我的代码显然不起作用,但应该给出一个想法,我试图做什么。我的代码目前不逐行处理数据,只处理td-by-td。你知道吗
我的理想代码是什么样的:
抓取第一个表行
检查第一列中的街道#是否匹配
如果#匹配,请抓取第三列中的链接
如果#不匹配,请检查下一个表格行
我对编程还是非常陌生的,所以我的代码仍然是笨拙的简单化(但是写得很糟糕)的。你知道吗
有问题的HTML
<tr>
<td class="transactionTableBodyText">5250 S RAINBOW BLVD 1001 </td>
<td class="transactionTableBodyText" align="center">SPRING VALLEY</td>
<td class="transactionTableBodyText" align="center">
<a id="DataGrid1__ctl3_HyperLink2" href="http://Sandgate.co.clark.nv.us/AssrRealProp/ParcelDetail.aspx?hdnParcel=16326214001&hdnInstance=pcl7" target="_self">163-26-214-001</a>
</td>
</tr>
我的吸血鬼密码。你知道吗
td = driver.find_elements_by_css_selector("td.transactionTableBodyText")
i = 0
while i <= len(td):
try:
if StrtNum in td[i].text:
print("We matched %s!" % (StrtNum))
#This is the incorrect part where I try to get to the 'a' selector in the 3rd column from the correctly identified 1st column.
ParcelLink = td[i+2].driver.find_elements_by_css_selector('a').get_attribute('href')
print(ParcelLink)
else:
return
except:
break
i+=1
另一个弓弦:lxml。它使您能够访问xpath表达式,从而简化导航HTML的工作。你知道吗
如您所见,我使用了REPL环境,这样我就可以尝试各种方法,同时尝试收敛到一些工作良好且看起来相当健壮的方法。你知道吗
差点忘了,这是我正在解析的HTML。你知道吗
相关问题 更多 >
编程相关推荐