Does somebody know how I can scrape websites read the URL list IE from a .txt and then write each url result to a .txt with using the name of a from a .txt. So there will be the URL and Name files the code reads from and writes the body with the respective line from the .txt file. The closest I've found is below code however that's saving it all into the one .txt file that is a fixed name not variable; and its reading the URLs from a list. I'm guessing a loop would be the best way however I haven't seen code or much help for this type of task.
import requests
from bs4 import BeautifulSoup
from collections import Counter
urls = ["http://en.wikipedia.org/wiki/Wolfgang_Amadeus_Mozart","http://en.wikipedia.org/wiki/Golf"]
with open('thisisanew.txt', 'w', encoding='utf-8') as outfile:
for url in urls:
website = requests.get(url)
soup = BeautifulSoup(website.content)
text = [''.join(s.findAll(text=True))for s in soup.findAll('p')]
for item in text:
print(item ,file=outfile,)
Thanks for your help in advance!
out:
Golf.txt:
Wolfgang_Amadeus_Mozart.txt