-1

How to write (i['src']) in a file.txt that I do not arrive ?

Here is my code

from bs4 import BeautifulSoup
import requests
import re

a = requests.get('domaine.com')
soup = BeautifulSoup(a.content, 'lxml')
links = soup.find_all('iframe')
for i in links:
    print(i['src'])
Keyur Potdar
  • 7,158
  • 6
  • 25
  • 40
kingos
  • 1
  • 2
  • Can you please clarify more on this line *How to write `(i['src'])` in a `file.txt` that I do not arrive ?* – Ali Mar 23 '18 at 17:51
  • thank you for your answer, I do not want to print, but stored in a text file ( .write ) sorry for my english i use google translate – kingos Mar 23 '18 at 17:56

1 Answers1

0

Check these answers: Correct way to write line to file?

Code:

from bs4 import BeautifulSoup
import requests
import re

a = requests.get('http://domaine.com')
soup = BeautifulSoup(a.content, 'lxml')
links = soup.find_all('iframe')
f = open('file.txt', 'a')
for i in links:
    f.write(str(i['src']) + '\n')

Output of file.txt:

https://www.googletagmanager.com/ns.html?id=GTM-M6RJ9CB
Ali
  • 1,357
  • 2
  • 12
  • 18