我想輸入一個網址列表,並抓住pn2和main1。我可以在不導入文件的情況下運行它,所以我知道它可行,但我不知道如何處理導入。這是我最近嘗試過的,下面是一小部分網址。提前致謝。python美麗湯進口網址
import urllib
import urllib.request
import csv
from bs4 import BeautifulSoup
csvfile = open("ecco1.csv")
csvfilelist = csvfile.read()
theurl="csvfilelist"
soup = BeautifulSoup(theurl,"html.parser")
for row in csvfilelist:
for pn in soup.findAll('td',{"class":"productText"}):
pn2.append(pn.text)
for main in soup.find_all('div',{"class":"breadcrumb"}):
main1 = main.text
print (main1)
print ('\n'.join(pn2))
的url: http://www.eccolink.com/products/productresults.aspx?catId=2458 http://www.eccolink.com/products/productresults.aspx?catId=2464 http://www.eccolink.com/products/productresults.aspx?catId=2435 http://www.eccolink.com/products/productresults.aspx?catId=2446 http://www.eccolink.com/products/productresults.aspx?catId=2463
你有什麼問題?也許你想'csvfile.readlines()' – maxymoo
我沒有收到錯誤,但它完成沒有結果 – PatrickP76
嘗試csvfile.readlines(),但仍然沒有結果 – PatrickP76