I have trouble using the “get” function to read the URL taken from cell A1 in the excel file “tennis3.xlsx”. I have tried different solutions and I have no idea how to get it to read it and use it to get a webpage response. The problem probably starts at at ‘sheet[“A1”].value’.
I have applied this program through visual studio, with it using the chrome browser. The URL thats in cell A1 is https://www.betexplorer.com/tennis/atp-singles/paris/evans-daniel-nakashima-brandon/WAqNf5ao/.
edit: the actual issue I had with this was that I forgot to include the save function.
JavaScript
x
15
15
1
import requests
2
from bs4 import BeautifulSoup
3
from openpyxl import load_workbook
4
5
workbook = load_workbook(filename="tennis3.xlsx")
6
sheet = workbook.active
7
urlcell = sheet["A1"].value
8
9
response = requests.get(urlcell)
10
webpage = response.content
11
12
soup = BeautifulSoup(webpage, "html.parser")
13
14
sheet["B1"] = soup.select('h1 a')[0].text.replace(' ','_')
15
Advertisement
Answer
You need to save the changes you made:
JavaScript
1
19
19
1
import requests
2
from bs4 import BeautifulSoup
3
from openpyxl import load_workbook
4
5
filename = r"tennis3.xlsx"
6
7
workbook = load_workbook(filename=filename)
8
sheet= workbook['Sheet1']
9
urlcell = sheet["A1"].value
10
print(urlcell)
11
12
response = requests.get(urlcell)
13
webpage = response.content
14
15
soup = BeautifulSoup(webpage, "html.parser")
16
17
sheet["B1"] = soup.select('h1 a')[0].text.replace(' ','_')
18
workbook.save(filename=filename)
19