I am using lxml to scrape data from a website. The html code snippet is
<span class="pro-contact-text">
<a class="click-to-call-link text-gray-light trackMe" href="javascript:;"
objId="104809" compid="clickToCall_profile_organic" phone="(617) 505-4149"">Click to Call</a>
</span>
I can get to the span by using the xpath (Eg. //*(some tags)/span[@class="pro-contact-text"
] ) and when I print the varible it prints a valid element (Eg. <Element span at 0x3589510>
)
When i extend the xpath to { span[@class="pro-contact-text"]/a/@phone
} it returns an empty list.
Can someone help me to do this.
答案 0 :(得分:0)
问题在于无效的html。
属性phone
以""
结尾(两个引号)。
phone="(617) 505-4149"">
^