import requests
from lxml import etree
#import time
from selenium import webdriver
import pandas as pd
from bs4 import BeautifulSoup
#需要将chromedriver放到Chrome\Application目录下
#chrome_driver=r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver_win32\chromedriver.exe"
chrome_driver=“C:\Program Files (x86)\Google\Chrome\Application\chromedriver_win32\chromedriver.exe”
driver = webdriver.Chrome(executable_path=chrome_driver)
request_url = ‘https://beijing.anjuke.com/sale/p’
print(html)
html = etree.HTML(html)
#print(html)
#去空格,去换行\n
def format_str(str):
return str.replace(’\n’, ‘’).replace(’ ', ‘’)
houses = pd.DataFrame(columns=[“name”, “details”, “address”, “price”])
for i in range(3):
url = request_url + str(i+1)
driver.get(url)
html = driver.find_element_by_xpath("//*&