Can you correct my Webscraping Script ,please ?


I have to search the internet (google chrome or Bing browser) for all the pharmacy (apothekes) of Kaiserslautern and Landkreis Kaiserslautern with at least 3 subsidiaries in Germany and obtain in an Excel table the url of these pharmacies, the name, the address, the email, telephone number and name of the Geschäftsführer( Manager).

I use an ISE Powershell script for this.

Here is my script:

I need to run as administrator first.

Then I type Set-execution policy (if restricted)

Get execution Policy


or open registry Editor via Key + R and type regedit and press enter.

Open the local group policy key + R and type gpedit.msc and press enter. If prompted by UAC, click on yes.

$Apotheken=”Kaiserslautern und Landkreis”

$url=” = contact information for $Apotheken”

$result=Invoke-WebRequest  $url

$elements=$results:All Elements|where class -eq “3 filialen”(in Germany)

$Apotheken = (Get-Service -DisplayName *Apotheken* | Select-Object -Property DisplayName, url,address,telefon,email address,Geschäftsführer Name)|Format-Table -Proprety  Name,url,Address,Telefon,Geschäftsführer Name| export “C:\temp\Apotheken.csv”

First off, I highly recommend that you set the execution policy to RemoteSigned, rather than Unrestricted. This will allow you to run locally written scripts, but require that any scripts from remote sources have a digital signature. Unrestricted is a dangerous policy to set.

As for your script, what problems are you experiencing with it? What error messages do you get when you run it? What does the output look like? Does it generate the csv as expected?

I’d recommend to use a specialized website like It will be probably much easier to scrape the results of such a specialized service.

Regardless of that I’d recommend as well to take a step back and start with learning the very basics of Powershell first. It’s not possible to learn a complex technology like a programming language by guessing or piecing together arbitrary snipptes of code you found on the internet.

Get-Service for example lists the services on a Windows computer. As long as you don’t have software installed on your computer providing a service with the name “Apotheken” it does not make sense to use Get-Service. And even if there would be such a service it would not have the properties DisplayName, url,address,telefon,email … and so on you’re trying to select with your Select-Object. :wink:

Sometimes it’s easier to ask complex questions in your native language - there is a German Microsoft Windows Powershell Forum - that might be helpful for you.