Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 如何将使用bs4的web scrape进程添加到Python中的selenium automation中,使其成为一个只需要zipcode的进程?_Python 2.7_Web Scraping_Selenium Chromedriver - Fatal编程技术网

Python 2.7 如何将使用bs4的web scrape进程添加到Python中的selenium automation中,使其成为一个只需要zipcode的进程?

Python 2.7 如何将使用bs4的web scrape进程添加到Python中的selenium automation中,使其成为一个只需要zipcode的进程?,python-2.7,web-scraping,selenium-chromedriver,Python 2.7,Web Scraping,Selenium Chromedriver,我正在使用selenium访问一个网站,然后转到搜索按钮键入我事先输入的zipcode,然后对于该邮政编码,我希望该网页必须为我使用beautiful soup创建的网页刮板提供链接,一旦链接出现,我可以刮取所需数据以获得我的csv 我想要的是: 我很难得到这个链接到美丽的汤网址。我基本上想让它自动化,这样我只需要输入一个邮政编码,它就会给我我的CSV 我能得到的: 我可以输入邮政编码并使用selenium进行搜索,然后将该url添加到我的scraper以获得csv 我用于selenium的代码

我正在使用selenium访问一个网站,然后转到搜索按钮键入我事先输入的zipcode,然后对于该邮政编码,我希望该网页必须为我使用beautiful soup创建的网页刮板提供链接,一旦链接出现,我可以刮取所需数据以获得我的csv

我想要的是: 我很难得到这个链接到美丽的汤网址。我基本上想让它自动化,这样我只需要输入一个邮政编码,它就会给我我的CSV

我能得到的: 我可以输入邮政编码并使用selenium进行搜索,然后将该url添加到我的scraper以获得csv

我用于selenium的代码:

driver = webdriver.Chrome('/Users/akashgupta/Desktop/Courses and Learning/Automating Python and scraping/chromedriver')
driver.get('https://www.weather.gov/')
messageField = driver.find_element_by_xpath('//*[@id="inputstring"]')
messageField.click()
messageField.send_keys('75252')
time.sleep(3)
showMessageButton = driver.find_element_by_xpath('//*[@id="btnSearch"]')
showMessageButton.click()


#web scraping Part:


url="https://forecast.weather.gov/MapClick.php?lat=32.99802500000004&lon=-96.79775499999994#.Xo5LnFNKgWo"
res= requests.get(url)
soup=BeautifulSoup(res.content,'html.parser')
tag=soup.find_all('div',id='seven-day-forecast-body')
weekly=soup.find_all(class_='tombstone-container')
main=soup.find_all(class_='period-name')
description=soup.find_all(class_='short-desc')
temp=soup.find_all(class_='temp')
Period_Name=[]
Desc=[]
Temp=[]
for a in range(0,len(main)):
    Period_Name.append(main[a].get_text())
    Desc.append(description[a].get_text())
    Temp.append(temp[a].get_text())
df = pd.DataFrame(list(zip(Period_Name, Desc,Temp)),columns =['Period_Name', 'Short_Desc','Temperature']) 


谢谢@sammyyy。这非常有效。你能推荐一些好的硒资源来深入了解硒吗。?
from selenium import webdriver
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://www.weather.gov/')
messageField = driver.find_element_by_xpath('//*[@id="inputstring"]')
messageField.click()
messageField.send_keys('75252')
time.sleep(3)
showMessageButton = driver.find_element_by_xpath('//*[@id="btnSearch"]')
showMessageButton.click()

WebDriverWait(driver, 10).until(EC.url_contains("https://forecast.weather.gov/MapClick.php")) # here you are waiting until url will match your output pattern

currentURL = driver.current_url
print(currentURL)
time.sleep(3)
driver.quit()

#web scraping Part:

res= requests.get(currentURL)
....