1 回答

TA貢獻2065條經(jīng)驗 獲得超14個贊
只需在文件名后附加一個字符串:
import urllib
from bs4 import BeautifulSoup
import pandas as pd
import time
i = []
crawl = pd.read_excel('C:/Users/Acer/Desktop/internal_all2.xlsx')
addresses = crawl['Address'].tolist()
for row in addresses:
url = row
time.sleep(5)
response = urllib.request.urlopen(url)
soup = BeautifulSoup(response, 'html.parser')
content = soup.find_all('p')
for content2 in content:
print(url, content2)
i.append([url,content2])
df = pd.DataFrame(i)
df.to_csv(f'C:/Users/Acer/Desktop/scripts/content/test_{url}.txt', index=False)
添加回答
舉報