我使用Python 2.7编写了这个刮刀,从TrueLocal.com.au的前3页获取链接,并将它们写入文本文件.
当我运行程序时,只有第一个链接写在文本文件中.我可以做什么,以便返回的所有URL都写在文件上?
import requests
from bs4 import BeautifulSoup
def tru_crawler(max_pages):
page = 1
while page <= max_pages:
url = 'http://www.truelocal.com.au/find/car-rental/' + str(page)
code = requests.get(url)
text = code.text
soup = BeautifulSoup(text)
for link in soup.findAll('a', {'class':'name'}):
href = 'http://www.truelocal.com.au' + link.get('href')
fob = open('c:/test/true.txt', 'w')
fob.write(href + '\n')
fob.close()
print (href)
page += 1
#Run the function
tru_crawler(3)
Run Code Online (Sandbox Code Playgroud) 我的“添加到购物车”按钮有以下代码
#addToCart {
background-color: #00AFEF;
border-radius: 10px;
width: 300px;
height: 50px;
font-size: 18px;
font-weight: bold;
}
Run Code Online (Sandbox Code Playgroud)
我想在按钮上添加悬停效果,使颜色深 10%。