【发布时间】:2020-08-09 06:54:46
【问题描述】:
如何将 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
【问题讨论】:
标签: python beautifulsoup python-requests text-files readline