我有一个网站,我想从哪里刮优惠券代码,我有两个问题here.Am使用蟒蛇和美丽汤在这里。1)在span标签中显示的一些优惠券没有类或id,因此无法从这些标签中获得优惠券。我需要从强标签(AXISCB50)获得优惠券。
<h6><span style="color: #808000">25% Cashback on Recharges :</span></h6>
<ul>
<li>Get 25% Cashback upto Rs.25 per transaction.</li>
<li>Coupon Code : <span style="color: #ff0000"><strong>AXISCB50</strong></span></li>
<li>Maximum 2 transaction per Debit/Credit card.</li>
</ul>是否可以通过指定style=“颜色:#808000类似于此(样式)”进行刮擦。
2)一些优惠券是通过ajax显示的,而ajax只在单击button.How之后才会显示,我会通过脚本显示这些数据吗?
对于第一个time.Any帮助,我非常感谢和感谢。
发布于 2015-03-08 07:32:00
要获得优惠券代码,我将不依赖于颜色样式属性。相反,将http://www.crummy.com/software/BeautifulSoup/bs4/doc/#next-element-and-previous-element转到Coupon Code文本。
soup.find(text=lambda x: x and x.startswith('Coupon Code')).next_element.text演示:
>>> from bs4 import BeautifulSoup
>>>
>>> data = """
... <h6><span style="color: #808000">25% Cashback on Recharges :</span></h6>
... <ul>
... <li>Get 25% Cashback upto Rs.25 per transaction.</li>
... <li>Coupon Code : <span style="color: #ff0000"><strong>AXISCB50</strong></span></li>
... <li>Maximum 2 transaction per Debit/Credit card.</li>
... </ul>
... """
>>>
>>> soup = BeautifulSoup(data)
>>>
>>> print soup.find(text=lambda x: x.startswith('Coupon Code')).next_element.text
AXISCB50有些优惠券是通过ajax显示的,ajax只在我们单击button.How之后才显示,我会通过脚本显示这些数据吗?
当您单击一个按钮时,您将需要研究发送什么请求。使用浏览器开发工具,网络选项卡。然后,在python代码中模拟请求。requests通常是一个不错的选择。
https://stackoverflow.com/questions/28923874
复制相似问题