现在就开始应用,了解更多URL
from urllib.request import urlopen
from bs4 import BeautifulSoup
import json, requests, re
AMEXurl = ['https://www.americanexpress.com/in/credit-cards/all-cards/?sourcecode=A0000FCRAA&cpid=100370494&dsparms=dc_pcrid_408453063287_kword_american%20express%20credit%20card_match_e&gclid=Cj0KCQiApY6BBhCsARIsAOI_GjaRsrXTdkvQeJWvKzFy_9BhDeBe2L2N668733FSHTHm96wrPGxkv7YaAl6qEALw_wcB&gclsrc=aw.ds']
identity = ['filmstrip_container']
html_1 = urlopen(AMEXurl[0])
soup_1 = BeautifulSoup(html_1,'lxml')
address = soup_1.find('div',attrs={"class" : identity[0]})
for x in address.find_all('a',id = 'html-link'):
print(x)
我得到的输出链接不起作用:
<a href="https://global.americanexpress.com/acq/intl/dpa/japa/ind/pers/begin.do?perform=IntlEapp:IND:platinum_charge&intlink=in-amex-cardshop-allcards-apply-AmericanExpressPlatinum-carousel&cpid=100370494&sourcecode=A0000FCRAA" id="html-link"><div><span>Apply Now</span></div></a>
<a href="charge-cards/platinum-card/?linknav=in-amex-cardshop-allcards-learn-AmericanExpressPlatinum-carousel&cpid=100370494&sourcecode=A0000FCRAA" id="html-link"><div><span>Learn More</span></div></a>
<a href="https://global.americanexpress.com/acq/intl/dpa/japa/ind/pers/begin.do?perform=IntlEapp:IND:platinum_charge&intlink=in-amex-cardshop-allcards-apply-AmericanExpressPlatinum-carousel&cpid=100370494&sourcecode=A0000FCRAA" id="html-link"><div><span>Apply Now</span></div></a>
<a href="charge-cards/platinum-card/?linknav=in-amex-cardshop-allcards-learn-AmericanExpressPlatinum-carousel&cpid=100370494&sourcecode=A0000FCRAA" id="html-link"><div><span>Learn More</span></div></a>
下面是html代码的图像,我试图从中获取“了解更多”和“了解更多”URL:
这是我想从中获取URL的页面部分:
我想知道代码中是否有任何更改,以便我获得所有“立即应用”并了解所有7张卡的URL
你可以修改它来使用你的列表和语法,但是这会得到我相信你想要的链接。请注意,使用
find
并不能获得所需的内容,但是使用find_all
和href=True
并获取第一个链接就可以了输出
您要查找的URL并非全部存储在HTML中。需要进一步的请求来返回JSON中的信息。为此,还需要会话ID。例如:
这将为您提供以下链接:
了解更多URL需要添加站点的基本URL
相关问题 更多 >
编程相关推荐