2024-04-23 12:04:43 发布
网友
我在python2.7中使用lxml.html文件我需要做以下事情。。。你知道吗
1)找出这一行是否在页面上。我其实是想看看父母是否存在。不是每页都有。你知道吗
DetailPage.StateController.setState('parent_asin', 'B0000DB87U');
2)如果存在,如何获取b000db87u?当父项在页面中时,每个页面的情况都会改变。这些都是javascript的,我使用lxml来获取和解析html。需要另一种JS方法。你知道吗
您可以使用lxml提取<script>标记的所有内容,然后用regex解析它们。你知道吗
<script>
未经测试的示例:
doc = lxml.html.parse(url) scripts = doc.xpath('//script') for script in scripts: match = re.findall(r"DetailPage\.StateController\.setState\('parent_asin', '(.*)'\);", script.text) if match: print match[0]
您可以使用lxml提取
<script>
标记的所有内容,然后用regex解析它们。你知道吗未经测试的示例:
相关问题 更多 >
编程相关推荐