如何将 txt.file 中的行读入此脚本,而不必在脚本中列出 url?谢谢
from bs4 import BeautifulSoup
import requests
url = "http://www.url1.com"
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data, 'html.parser')
categories = soup.find_all("a", {"class":'navlabellink nvoffset nnormal'})
for category in categories:
print(url + "," + category.text)
我的 text.file 内容有换行符分隔符:
http://www.url1.com
http://www.url2.com
http://www.url3.com
http://www.url4.com
http://www.url5.com
http://www.url6.com
http://www.url7.com
http://www.url8.com
http://www.url9.com
千万里不及你
郎朗坤
不负相思意
相关分类