Locally noetherian schemes I'm reading Algebraic Geometry written by R. Hartshorne. There is a proposition in section 3, I have few problems with a part of its proof

A scheme $X$ is locally noetherian iff for every open subset $U=\operatorname{Spec} A$, $A$ is noetherian.

Let $X=\operatorname{Spec} A$ be an affine scheme, we want to prove $A$ is noetherian. In this regard let $U=\operatorname{Spec} B$, where $B$ is noetherian, be an open subset. There exists $f\in A$ so that $D(f)\subset \operatorname{Spec} B$; Moreover, suppose $\bar{f}$ is the image of $f$ in $B$ then we have $A_f\cong B_{\bar{f}}$.
My problem is that I'm not sure how $f$ is chosen and why $A_f\cong B_{\bar{f}}$ is correct.
My attempt: Let $f_1\in A-B$, for each $p\in \operatorname{Spec} A$ for which we have $p\in D(f_1)$, let $g$ be a member in $p-B$ and define $f_2=f_1g$. Continue these steps until there is no such $p\in \operatorname{Spec} A$.
 A: The existence of $f$ follows from the fact that the open sets $D(f)$ form a base for the topology on $\operatorname{Spec} A$: every open set in $\operatorname{Spec} A$ is the union of some sets of the form $D(f)$, so if $\operatorname{Spec} B\subset\operatorname{Spec} A$ is an open subset, there's an $f$ so that $D(f)\subset \operatorname{Spec} B$.
Next, to see that $D(f)\subset \operatorname{Spec} A$ is the same set as $D(\overline{f})\subset \operatorname{Spec} B$, the first thing to note is that $\overline{f}$ is the restriction of $f\in\mathcal{O}_{\operatorname{Spec} A}(\operatorname{Spec} A)$ to $\mathcal{O}_{\operatorname{Spec} A}(\operatorname{Spec} B)$. So if $p$ is a point in $\operatorname{Spec} B$, $f$ and $\overline{f}$ have the same image in $\mathcal{O}_{\operatorname{Spec} A,p}=\mathcal{O}_{\operatorname{Spec} B,p}$.
As a point $p$ is in $D(f)$ iff $f$ is not in the maximal ideal of the local ring at $p$, we see that $D(\overline{f})=\operatorname{Spec} B \cap D(f)$, and as $D(f)\subset \operatorname{Spec} B$, we get that $D(\overline{f})=D(f)$.
Finally, as $\mathcal{O}_{\operatorname{Spec} A}(D(f))\cong A_f$ and $\mathcal{O}_{\operatorname{Spec} B}(D(\overline{f}))\cong B_{\overline{f}}$, we see that $A_f\cong B_{\overline{f}}$.
