Я хочу найти все ссылки на странице, этот код получает только ссылки, начинающиеся с http://
, однако большинство ссылок https://
как я могу отредактировать код ниженайти оба?
for link in soup.find_all('a',attrs={'href':re.compile("^http://")}):
import requests,bs4,re
res=requests.get('https://www.nytimes.com/2018/11/21/nyregion/president-trump-immigration-law-firms.html?action=click&module=Top%20Stories&pgtype=Homepage')
soup=bs4.BeautifulSoup(res.text,'html.parser')
x=[]
y=[]
z=[]
for link in soup.find_all('a',attrs={'href':re.compile("^http://")}):
print(link.get('href'))
x=link.get('href')
Я знаю, что могу просто получить все ссылки, но я хотел получить и http://
, и https://
в одном find_all
for i in soup.select('a'):
print(i.get('href'))