【发布时间】:2017-05-01 06:17:18
【问题描述】:
我正在迭代一个过程,在该过程中,我将 Python 引导到一个网站,并指示 Python 在指定网站的 csv 文件中查找我的地址。我想告诉 Python 将网站中每个地址值的结果保存到 csv 文件中。
from selenium import webdriver
from bs4 import BeautifulSoup
import time
import csv
driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe")
chrome = driver.get('https://etrakit.friscotexas.gov/Search/permit.aspx')
with open('C:/Users/thefirstcolumnedited.csv','r') as f:
addresses = f.readlines()
for address in addresses:
driver.find_element_by_css_selector('#cplMain_txtSearchString').clear()
driver.find_element_by_css_selector('#cplMain_txtSearchString').send_keys(address)
driver.find_element_by_css_selector('#cplMain_btnSearch').click()
time.sleep(5)
soup = BeautifulSoup(chrome, 'html.parser')
writer = csv.writer(open('thematchingresults.csv', 'w'))
writer.writerow(soup)
例如:
6579 Mountain Sky Rd
上面的地址值从网站检索五行数据。如何告诉 Beautiful Soup 将结果保存在 csv 文件中的每个地址值?
【问题讨论】:
标签: python python-2.7 csv web-scraping beautifulsoup